首页 > 代码库 > python编程快速上手之第9章实践项目参考答案(9.8.1)

python编程快速上手之第9章实践项目参考答案(9.8.1)

import os,shutil
newfolder=‘C:\\delicious\\test‘
sourcefolder=‘C:\\delicious‘
os.chdir(sourcefolder)
for folderName, subfolders, filenames in os.walk(sourcefolder):
#print (filenames)
  for item in filenames:
    if item.endswith(‘.txt‘):
      #print(item)
      shutil.copy(item , newfolder)
      print (‘Copy ‘+ item +‘ to ‘+newfolder )
    #else:
     #print(‘NONE‘)

python编程快速上手之第9章实践项目参考答案(9.8.1)