#!python3
#to copy some files like '.pdf .jpg etc'
#let me design it as a 'def'
#1.searching a dir to find what you wannna
import os,shutil
os.chdir('C:\\Users\\DELL\\Desktop')
#copy_year=open('.\\copy_year','w') open打不开文件夹?
#os.makedirs('C:\\Users\\DELL\\Desktop\\copy_year') #creat new dir as 3. remind
def movefiles(folder):
for foldername,subfolders,filenames in os.walk(folder):
#print('subfolders:"%s"',subfolders)
#print('foldername:"%s"',foldername)
for filename in filenames:
#print('filename:"%s"',filenames)
if filename.endswith('.docx'):
print('you will move"%s" to copy_year',filename)
shutil.copy(filename,'.\\copy_year') #just move
else:
continue
os.startfile('.\\copy_year')
#copy_year.close()
#2.creat new dir and use shutil to move the special files
#3.close folders
movefiles('.\\years')