您好,登錄后才能下訂單哦!
使用python怎么將文件按修改時間進行分類?很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學(xué)習(xí)下,希望你能有所收獲。
程序源碼如下:
#coding:utf-8 import os import sys import os.path import time from shutil import Error from shutil import copystat from shutil import copy2 path_str = r"D:\pic"; def copy_file(src_file, dst_dir): if os.path.isdir(dst_dir): pass; else: os.makedirs(dst_dir); print(src_file); print(dst_dir); copy2(src_file, dst_dir) def walk_file(file_path): for root, dirs, files in os.walk(file_path, topdown=False): for name in files: com_name = os.path.join(root, name); t=os.stat(com_name); copy_path_str = path_str+r"\year"+str(time.localtime(t.st_mtime).tm_year)+r"\month"+str(time.localtime(t.st_mtime).tm_mon); print(copy_path_str); copy_file(com_name,copy_path_str); for name in dirs: walk_file(name); walk_file(path_str);
看完上述內(nèi)容是否對您有幫助呢?如果還想對相關(guān)知識有進一步的了解或閱讀更多相關(guān)文章,請關(guān)注億速云行業(yè)資訊頻道,感謝您對億速云的支持。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。