-
Notifications
You must be signed in to change notification settings - Fork 0
/
M_File.py
112 lines (86 loc) · 2.69 KB
/
M_File.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
##############################
# import
##############################
import wx
import GUI_File
import os
from os.path import join, getsize
import win32file
import shutil
##############################
# GUI的函数桥接
##############################
class CalcFrame(GUI_File.Main):
def __init__(self, parent):
# 定义主函数
GUI_File.Main.__init__(self, parent)
Refresh_File(self)
Refresh_Log(self)
def Clean(self, event):
try:
shutil.rmtree('./Cache/')
os.mkdir('./Cache')
shutil.rmtree('./Log/')
os.mkdir('./Log')
except:
print('some file can not be deleted!')
Refresh_File(self)
Refresh_Log(self)
def MainOnShow(self, event):
if self.IsShown() == True:
Refresh_File(self)
Refresh_Log(self)
print('File:更新')
def Close(self, event):
self.Destroy()
##############################
# 主函数
##############################
def main():
global app
app = wx.App(False)
frame = CalcFrame(None)
frame.Show(True)
app.MainLoop()
def Refresh_File(self):
file_list = []
size = 0
for root, dirs, files in os.walk('./'):
for name in files:
file_list.append(root + '/' +name)
size += sum([getsize(join(root, name)) for name in files])
self.FileNum_ALL.SetLabel('本地文件数:' + str(len(file_list)))
self.FileSize_ALL.SetLabel('本地文件大小:' + str(round(size / 1024 / 1024)) + 'MB | ' + str(size) + '字节')
self.G_Size.SetValue(int(round(size / 1024 / 1024) / 10))
self.AlreadyUsed.SetLabel('%' + str(round(size / 1024 / 1024) / 10))
file_list = []
size = 0
for root, dirs, files in os.walk('./Cache/'):
for name in files:
file_list.append(root + '/' +name)
size += sum([getsize(join(root, name)) for name in files])
self.FileNum_Cache.SetLabel('缓存文件数:' + str(len(file_list)))
self.FileSize_Cache.SetLabel('缓存占用空间:' + str(round(size / 1024)) + 'KB | ' + str(size) + '字节')
def Refresh_Log(self):
file_list = []
size = 0
for root, dirs, files in os.walk('./Log/'):
for name in files:
file_list.append(root + '/' +name)
size += sum([getsize(join(root, name)) for name in files])
self.FileNum_Log.SetLabel('日志文件数:' + str(len(file_list)))
self.FileSize_Log.SetLabel('日志占用空间:' + str(round(size / 1024)) + 'KB | ' + str(size) + '字节')
def is_used(file_name):
'''
检测文件占用
'''
try:
v_handle = win32file.CreateFile(file_name, win32file.GENERIC_READ, 0, None, win32file.OPEN_EXISTING,
win32file.FILE_ATTRIBUTE_NORMAL, None)
result = bool(int(v_handle) == win32file.INVALID_HANDLE_VALUE)
win32file.CloseHandle(v_handle)
except Exception:
return True
return result
if __name__ == "__main__":
main()