用re,shutil模块进行文件移动

import os,zipfile,pprint,shutil,re
x=r"D:\纪检\综治\15"
os.chdir(x)                         #改变当前工作文件夹地址

reger_pptx=re.compile(r'(.*)(小组|名单)(.*)(\.doc|docx|xlsx|xls|rtf)')#创建Reger对象

for foldname,subfolds,filename in os.walk('.'):#用os.walk()函数遍历文件夹及文件
  for j in filename:#遍历文件名列表
     namelist= reger_pptx.search(j)
     if namelist==None:
       continue
     print(namelist.group(),foldname,sep='\t\t\t\t')
     shutil.copy(os.path.join(foldname,namelist.group()),r'D:\纪检\综治\新建文件夹 (2)')

猜你喜欢

转载自blog.csdn.net/weixin_42393848/article/details/86590343
今日推荐