代码:
my = os.path.abspath(r'C:\\Users\\user\\Desktop\\新建文件夹\\111')
cp = os.path.abspath(r'D:\\PicFile')
if not os.path.exists(cp):
os.makedirs(cp)
t = 0
q = 0
a = input('请输入需要查找到的文件扩展名:')
if os.path.exists(my):
for root, dirs, files in os.walk(my):
for file in files :
src_file = os.path.join(root, file)
if a in src_file:
q += 1
print('\n'
'==============共找到%d文件==============='
'\n' % (q))
if os.path.exists(my):
for root, dirs, files in os.walk(my):
for file in files :
src_file = os.path.join(root, file)
if a in src_file:
t = t + 1
print(t,src_file)
shutil.copy(src_file, cp)
shutil.make_archive('all_python','zip',base_dir='D:\\myFile')