import os import shutil def organize_files(folder_path): # 获取目录中的所有文件 files = os.listdir(folder_path) # 遍历所有文件 for filename in files: if os.path.isfile(os.path.join(folder_path, filename)): # 获取文件类型 file_extension = os.path.splitext(filename)[1].lower() # 创建对应类型的文件夹 folder_name = file_extension[1:] + "_files" folder_path_new = os.path.join(folder_path, folder_name) if not os.path.exists(folder_path_new): os.makedirs(folder_path_new) # 将文件移动到相应的文件夹中 file_path_old = os.path.join(folder_path, filename) file_path_new = os.path.join(folder_path_new, filename) shutil.move(file_path_old, file_path_new) print("Moved file:", filename, "to folder:", folder_name) # 在此处指定你希望整理的文件夹路径 folder_path = "E:\kcfile" # 调用整理文件函数 organize_files(folder_path)