直接上代碼python
↓windows
1 #! python3 2 # -*- coding: UTF-8 -*- 3 4 import os 5 import time 6 import shutil 7 8 #Windows聚焦圖片位置 9 #C:\Users\xxxxxx\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets 10 11 #定義 12 def rename(): 13 #path = r'C:\Users\xxxxxx\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets' 14 #newpath = r'D:\windows_focus'#新的保存路徑 15 path = r'C:\Users\xxxxxx\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets' 16 newpath = r'D:\windows_focus\images_'#新的保存路徑 17 18 dirtime = time.strftime("%Y%m%d%H%M") 19 20 if not os.path.exists(newpath+dirtime): 21 #os.mkdir(newpath+dirtime) 22 os.makedirs(newpath+dirtime) 23 24 i = 1 25 filelist = os.listdir(path)#獲取path文件夾下的全部文件 26 print('共計:'+str(len(filelist))+'個文件') 27 for files in filelist:#遍歷全部文件 28 Olddir = os.path.join(path, files)#原來的文件路徑 29 fileSize = os.path.getsize(Olddir) / 1024 30 print(i, ' ['+str(fileSize)+'KB] ', Olddir) 31 32 timeline = time.strftime("%Y%m%d%H%M%S")#獲取當前的時間,年月日時分秒 33 #Newdir = os.path.join(newpath, timeline+'_'+str(i)+'.jpg') 34 Newdir = os.path.join(newpath+dirtime, timeline+'_'+str(i)+'.jpg') 35 print('↓') 36 37 if fileSize > 150: 38 shutil.copyfile(Olddir, Newdir)#將原來路徑的文件複製到新的路徑下 39 print(i, ' ['+str(fileSize)+'KB] ', Newdir, '文件轉換 完成。') 40 else: 41 print(i, ' ['+str(fileSize)+'KB] ', Newdir, '文件過小 忽略!') 42 43 #注意縮進 44 pass#pass是空語句 45 print('') 46 i += 1 47 48 #調用 49 rename()