大家好,我在 python 中有这段代码用于“文件组织”代码工作没有任何问题
import fnmatch
import os
import shutil
import pathlib
temp_path = pathlib.Path(__file__).parent.resolve()
path = pathlib.PureWindowsPath(fr'{temp_path}').as_posix()
all_files = list()
extension = set()
#list of all the files and extensions
for entry in os.scandir(path):
if entry.is_file() and not fnmatch.fnmatch(entry, '*.ini'):
all_files.append(entry.name)
extension.add(os.path.splitext(entry)[1])
#creating the folders
for folder in extension:
folder_path = path+'/All_'+folder[1:]+'s/'
#creating the folder
os.mkdir(folder_path)
#check in the list of the files
for file in all_files:
if file.endswith(folder):
#moving the file from the current directory to the directory
shutil.move(path+'/'+file, folder_path+file)
代码应该获取文件并根据它们的扩展名将它们组织在文件夹中,当我运行 exe 文件时它不执行此任务,cmd 窗口像第二次打开一样关闭并且文件没有组织 我已经尝试了所有可能的方法:pyInstaller --onefile、Py2exe、auto-py-to-exe 等等…… 当我创建快捷方式并移动到另一个目录时,它在 dist 文件夹内部或外部不起作用,有谁知道问题出在哪里。 我的系统是:Windows10