MCPcopy Create free account
hub / github.com/XUANXUQAQ/File-Engine / delDir

Function delDir

build.py:83–103  ·  view source on GitHub ↗

清理空文件夹和空文件 param path: 文件路径,检查此文件路径下的子文件

(path)

Source from the content-addressed store, hash-verified

81
82
83def delDir(path):
84 """
85 清理空文件夹和空文件
86 param path: 文件路径,检查此文件路径下的子文件
87 """
88 try:
89 files = os.listdir(path) # 获取路径下的子文件(夹)列表
90 for file in files:
91 if os.path.isdir(os.fspath(path+'/'+file)): # 如果是文件夹
92 if not os.listdir(os.fspath(path+'/'+file)): # 如果子文件为空
93 os.rmdir(os.fspath(path+'/'+file)) # 删除这个空文件夹
94 else:
95 delDir(os.fspath(path+'/'+file)) # 遍历子文件
96 if not os.listdir(os.fspath(path+'/'+file)): # 如果子文件为空
97 os.rmdir(os.fspath(path+'/'+file)) # 删除这个空文件夹
98 elif os.path.isfile(os.fspath(path+'/'+file)): # 如果是文件
99 if os.path.getsize(os.fspath(path+'/'+file)) == 0: # 文件大小为0
100 os.remove(os.fspath(path+'/'+file)) # 删除这个文件
101 return
102 except FileNotFoundError:
103 print("文件夹路径错误")
104
105
106def getFileMd5(file_name):

Callers 1

delFileInZipFunction · 0.85

Calls 1

printFunction · 0.85

Tested by

no test coverage detected