Python将多个文件夹下的多个文件复制到制定文件夹中

Python将多个文件夹下的多个文件复制到制定文件夹中

将这4个文件里面的txt和jpg里面整合到某个文件夹下面

Python将多个文件夹下的多个文件复制到制定文件夹中

整合到这个文件夹下面
Python将多个文件夹下的多个文件复制到制定文件夹中

import os
import shutil

print(‘输入格式:D:\test\test’)
path = input(‘请键入需要整理的文件夹地址:’)
new_path = input(‘请键入要复制到的文件夹地址:’)

for root, dirs, files in os.walk(path):
for i in range(len(files)):
# print(files[i])
if (files[i][-3:] == ‘jpg’) or (files[i][-3:] == ‘txt’):
file_path = root + ‘/’ + files[i]
new_file_path = new_path + ‘/’ + files[i]
shutil.copy(file_path, new_file_path)

ps:代码是从某个大神那里复制过来的:
https://blog.csdn.net/xuan314708889/article/details/79619732

如果写好的exe文件不能粘贴复制的情况,采用下面的方法:

Python将多个文件夹下的多个文件复制到制定文件夹中

Python将多个文件夹下的多个文件复制到制定文件夹中

将快速编辑勾选上