-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_list.py
38 lines (29 loc) · 999 Bytes
/
file_list.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from os import listdir, remove
from os.path import isfile, join, getsize
import math
def get_file_list():
# -- get file name from directory
fileList = [f for f in listdir("./compressed/") if isfile(join("./compressed/", f))]
# -- get size
for i in range(len(fileList)):
size = getsize("./compressed/" + fileList[i])
# -- count size
size_name = ("B", "KB", "MB", "GB")
j = int(math.floor(math.log(size, 1024)))
p = math.pow(1024, j)
s = round(size / p, 2)
# -- append to list
fileList[i] = (fileList[i], "%s %s" % (s, size_name[j]))
return fileList
def get_file_size(name):
size = getsize("./compressed/" + name)
# -- count size
size_name = ("B", "KB", "MB", "GB")
j = int(math.floor(math.log(size, 1024)))
p = math.pow(1024, j)
s = round(size / p, 2)
res = "%s %s" % (s, size_name[j])
return res
def remove_file(name):
remove("./compressed/" + name)
return "Success"