分享

Python

 乙甲壬 2020-07-06
#将以 't[年份]开头的文件移动到各自的文件夹中 import os import shutil filelist =os.listdir(r'D:\temp_daily19712014') base ='D:/temp_daily19712014/' for year in range(1971,2015): subdir =base + str(year) os.mkdir(subdir) #建立子文件夹#shutil.move('d:/test/1962.txt','d:/test/1962/1962.txt') for filesin filelist: for year in range(1971, 2015): oldpos =os.path.join(base, files) #原先路径 newpos = os.path.join(base +str(year), files) #目标路径 if files.startswith('t' + str(year)):#判断是否以t[year]开头 shutil.move(oldpos, newpos ) #移动

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多