Skip to content

Commit

Permalink
Update filemanager.py to fix filesize issues
Browse files Browse the repository at this point in the history
Fix filesize issues #146
  • Loading branch information
meramsey authored Nov 23, 2023
1 parent 589f87a commit 5bbebe4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion filemanager/filemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ def changeOwner(self, path):
except:
print("Permisson not changed")


def bytes_to_human_readable(num, suffix='B'):
for unit in ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z']:
if abs(num) < 1024.0:
return "%3.1f%s%s" % (num, unit, suffix)
num /= 1024.0
return "%.1f%s%s" % (num, 'Yi', suffix)


def listForTable(self):
try:
finalData = {}
Expand Down Expand Up @@ -221,7 +230,7 @@ def listForTable(self):
if currentFile[0][0] == 'd':
dirCheck = 1

size = str(int(int(currentFile[4]) / float(1024)))
size = bytes_to_human_readable(int(currentFile[4]))
lastModified = currentFile[5] + ' ' + currentFile[6] + ' ' + currentFile[7]
finalData[str(counter)] = [currentFile[-1], currentFile[-1], lastModified, size, currentFile[0],
dirCheck]
Expand Down

0 comments on commit 5bbebe4

Please sign in to comment.