You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
960 B
38 lines
960 B
import os |
|
|
|
|
|
def get_file_list(_path): |
|
file_gen = os.walk(_path) |
|
file_list = [] |
|
for item in file_gen: |
|
if len(item[2]): |
|
for file in item[2]: |
|
file_list.append(os.path.join(item[0], file)) |
|
return file_list |
|
|
|
|
|
def get_empty_folder_list(path): |
|
folder_list = [] |
|
for f in os.walk(path): |
|
if len(f[2]) == 0 and len(f[1]) == 0: |
|
folder_list.append(f[0]) |
|
return folder_list |
|
|
|
|
|
def remove_empty_folder(path): |
|
del_folder_list = [] |
|
del_folder_list.extend(get_empty_folder_list(path)) |
|
|
|
while len(del_folder_list) > 0: |
|
for f in del_folder_list: |
|
if os.path.exists(f): |
|
print(f"删除空文件夹 {f}") |
|
os.rmdir(f) |
|
del_folder_list = [] |
|
del_folder_list.extend(get_empty_folder_list(path)) |
|
|
|
|
|
if __name__ == "__main__": |
|
result = get_file_list(r"E:\Backup\Tools\Normal\浏览器") |
|
for r in result: |
|
print(r)
|
|
|