Skip to content

Commit 962ca10

Browse files
committed
Update main.py
1,取消对C盘的强制判定,改为弹窗由用户确认,但仍可能由于权限不足而无法正常工作。仍然建议用户不要在C盘路径下进行操作。 2,新增3个白名单文件
1 parent 30c4b72 commit 962ca10

1 file changed

Lines changed: 24 additions & 19 deletions

File tree

main.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"pythonw.exe",
2929
"VCRUNTIME140_1.dll",
3030
],
31-
"matplotlib": ["matplotlibrc", ".load-order","matplotlib.svg"],
31+
"matplotlib": ["matplotlibrc", ".load-order", "matplotlib.svg"],
3232
"request": ["msgcat-1.6.1.tm"],
3333
"plotly": ["plotly.json", "plotly.min.js", "package_data\\templates"],
3434
"pyecharts": ["pyecharts"],
@@ -41,8 +41,10 @@
4141
],
4242
"streamlit": ["streamlit\\static"],
4343
"trame_vtk": ["static_viewer.html"],
44+
"python-docx": ["docx\\templates"],
45+
"python-pptx": ["pptx\\templates"],
4446
}
45-
WHITE_FILE_TYPE = [".pyi", ".py",".pyc", ".pth", "._pth"]
47+
WHITE_FILE_TYPE = [".pyi", ".py", ".pyc", ".pth", "._pth"]
4648

4749

4850
class WinGUI(Tk):
@@ -252,12 +254,6 @@ def select_file(self) -> None:
252254
if selected_path == "":
253255
return
254256
selected_path = Path(selected_path)
255-
# 为了避免误操作C盘重要文件,本程序不允许在C盘进行操作
256-
if "C" in selected_path.drive:
257-
messagebox.showinfo(
258-
title="警告", message="本程序不支持在C盘路径下进行操作,请重选路径!"
259-
)
260-
return
261257
self.tk_input_file.delete(0, "end")
262258
self.tk_input_file.insert(0, str(selected_path))
263259

@@ -278,7 +274,7 @@ def work_thread_func(self, white_list: list[str], file_path: Path) -> None:
278274
file_count = len(file_list)
279275
for idx, filename in enumerate(file_list):
280276
if FileRemove.check_file(white_list, filename) and (
281-
not FileRemove.is_file_in_use(filename)
277+
not FileRemove.is_file_in_use(filename)
282278
): # 检查白名单和占用
283279
relative_path = filename.relative_to(file_path)
284280
filename_new = file_dir_new.joinpath(relative_path)
@@ -291,9 +287,15 @@ def work_thread_func(self, white_list: list[str], file_path: Path) -> None:
291287

292288
if file_trans_lst.exists():
293289
os.remove(str(file_trans_lst))
294-
with open(file_trans_lst, "w", encoding="utf-8") as file:
295-
for temp_file in file_move_lst:
296-
file.write(f"{temp_file}\n")
290+
try:
291+
with open(file_trans_lst, "w", encoding="utf-8") as file:
292+
for temp_file in file_move_lst:
293+
file.write(f"{temp_file}\n")
294+
except PermissionError:
295+
messagebox.showerror(
296+
title="错误", message="权限不足,考虑用管理员权限重新运行程序"
297+
)
298+
return
297299
messagebox.showinfo("提示", "文件移动结束!")
298300
self.tk_button_start.config(state=ACTIVE)
299301

@@ -305,11 +307,14 @@ def start_work(self):
305307
file_path = Path(file_path)
306308
if not file_path.exists():
307309
return
310+
# 为了避免误操作C盘重要文件,本程序不允许在C盘进行操作
308311
if "C" in file_path.drive:
309-
messagebox.showinfo(
310-
title="警告", message="本程序不支持在C盘路径进行操作,请重选路径!"
312+
result = messagebox.askokcancel(
313+
title="警告",
314+
message=f"检测到当前需要处理的路径为C盘路径,\n程序可能因为权限不足无法正常工作。请确认是否执行\n待处理文件夹:{file_path}",
311315
)
312-
return
316+
if not result:
317+
return
313318
self.tk_progressbar_progress.config(value=0)
314319

315320
file_move_thread = threading.Thread(
@@ -410,12 +415,12 @@ def move_file_to_folder(file_old: Path, file_new: Path) -> None:
410415
if not file_new.parent.exists():
411416
try:
412417
os.makedirs(file_new.parent)
413-
except (PermissionError, FileNotFoundError):
414-
pass
418+
except (PermissionError, FileNotFoundError) as e:
419+
print(e)
415420
try:
416421
file_old.rename(file_new)
417-
except Exception:
418-
pass
422+
except Exception as e:
423+
print(e)
419424

420425
@staticmethod
421426
def check_file(white_list: list[str], file: Path) -> bool:

0 commit comments

Comments
 (0)