将相同文件名的文件,放到同一个目录中,利用 python
实现
import shutil
import os
# 将相同文件名的文件,放到同一个目录中
path = r'C:\Users\xxx\Desktop\vvvv'
files_list = os.listdir(path)
for file in files_list:
filename, suffix = os.path.splitext(file)
new_path = path + "\\" + filename
if not os.path.exists(new_path):
os.makedirs(new_path)
print("新建目录为:", new_path)
src_file = path + "\\" + file
new_file = new_path + "\\" + file
shutil.copyfile(src_file, new_file)
print("源文件目录为:" + src_file, "目标文件目录为:" + new_file)