批量归类文件

    xiaoxiao2022-06-30  71

    #将以 '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 files in 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 ) #移动
    转载请注明原文地址: https://ju.6miu.com/read-1125914.html

    最新回复(0)