This repository has been archived by the owner on Aug 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-win.py
121 lines (108 loc) · 4.02 KB
/
run-win.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import sys
import ctypes
import subprocess
import foldersize as fs
# windows runtime
def is_admin():
try:
return ctypes.windll.shell32.IsUserAnAdmin()
except:
return False
def cmd_spl(command):
try:
command = command.partition(' ')
return command[0], command[2]
except:
return command, ''
helpmsg = '''
Enter help(h) to get help message
Enter scan(s) [path] to scan all folders and files below the path specified
Enter treeview(t) [optional=level / -full(f)] to print the scan\'s result
the folders below the level will be collapsed
default value is 5 level should be upper than 1
use option -full(f) to print the full scan\'s result
Enter dirlistview(dl) [optional=number / -full(f)] to print the folders\' paths descending by size
number can be specified to decide the number of paths you want to display
default value is 10
use option -full(f) to print the full result
Enter filelistview(fl) [optional=number / -full(f)] to print the files\' paths descending by size
number can be specified to decide the number of paths you want to display
default value is 10
use option -full(f) to print the full result
Enter go(g) [index] to move into the specified folder
index relates to the treeview
Enter back(b) to return to the previous folder
Enter open(o) [index] to open the folder or the file specified
index relates to the last showed view
Enter exit(e) to exit'''
if is_admin():
pass
else:
print('Permission is needed to access the system files\n' +
'Would you like to request the permission(y/n)?')
inputsrc = input()
if inputsrc == 'y':
ctypes.windll.shell32.ShellExecuteW(
None, "runas", sys.executable, __file__, None, 1)
sys.exit()
else:
pass
print()
print('Enter help(h) to get help message')
foldersize = None
while True:
print()
print('> Enter command:')
inputsrc = input()
cmd, cont = cmd_spl(inputsrc)
print()
try:
if cmd == 'help' or cmd == 'h':
print(helpmsg)
elif cmd == 'scan' or cmd == 's':
print('Scan started...')
foldersize = fs.FolderSize(cont)
foldersize.scan_dir()
print('Scan completed...')
elif cmd == 'treeview' or cmd == 't':
if cont == '-full' or cont == '-f':
foldersize.print_treeview(collapse=False)
elif cont != '':
foldersize.print_treeview(level=int(cont))
else:
foldersize.print_treeview()
elif cmd == 'dirlistview' or cmd == 'dl':
if cont == '-full' or cont == '-f':
foldersize.create_dir_list(full=True)
elif cont != '':
foldersize.create_dir_list(number=int(cont))
else:
foldersize.create_dir_list()
foldersize.print_listview(fs.ViewType.DirList)
elif cmd == 'filelistview' or cmd == 'fl':
if cont == '-full' or cont == '-f':
foldersize.create_file_list(full=True)
elif cont != '':
foldersize.create_file_list(number=int(cont))
else:
foldersize.create_file_list()
foldersize.print_listview(fs.ViewType.FileList)
elif cmd == 'go' or cmd == 'g':
foldersize.movein(int(cont))
foldersize.print_treeview(level=2)
elif cmd == 'back' or cmd == 'b':
foldersize.back_action()
foldersize.print_treeview(level=2)
elif cmd == 'open' or cmd == 'o':
path = foldersize.get_elem(int(cont))
subprocess.run(f'explorer /select,{path}')
print(path + ' opened')
elif cmd == 'exit' or cmd == 'e':
break
else:
print('Do not have such a command')
except AttributeError:
print('Operation invaild: Scan first')
except Exception as ex:
print('Operation invaild:', ex)
exit()