-
Notifications
You must be signed in to change notification settings - Fork 0
/
Directories.py
78 lines (55 loc) · 1.95 KB
/
Directories.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from pathlib import Path
import platform
class Directories:
@staticmethod
def getOnlyDir(location = '/'):
DIR = Path(location).iterdir()
DIRS = []
for item in DIR:
if item.is_dir():
DIRS.append(item.__str__())
return {
"path" : location,
'dirs' : DIRS
}
@staticmethod
def getDirData(location = '/'):
DIR = Path(location).iterdir()
data = []
for item in DIR:
fullPath = item.__str__()
extension = ''
mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime = item.stat()
fSize = float(size / 1048576)
size_in_str = str(round(fSize, 1)) + 'MB'
if int(fSize) <= 0:
size_in_str = str(round(fSize * 1024, 1)) + 'KB'
elif int(fSize) >= 1024:
size_in_str = str(round(fSize / 1024, 2)) + 'GB'
if not item.is_dir() and fullPath.find('.') > 0:
extension = fullPath[fullPath.rfind('.') : ]
data.append({
"name": fullPath[fullPath.rfind('\\' if platform.system() == 'Windows' else '/') + 1:],
"extension" : extension,
"is_dir" : item.is_dir(),
"stat" : mtime,
"size" : size_in_str
})
return {
"path" : location,
'data' : data
}
@staticmethod
def previousFolder(location:str):
if location == '/':
return None
if location.rfind('/') == 0:
return Directories.getData()
return Directories.getData(location[0 : location.rfind('/')])
@staticmethod
def nextFolder(currentPath = '/', location = ''):
if currentPath == '/':
location = currentPath + location
else:
location = currentPath + '/' + location
return Directories.getData(location)