9行python程式碼批量修改window屏保圖檔案
阿新 • • 發佈:2018-12-24
前言
最近看到window10開機桌布特別好看,想去儲存下來,查到其原始檔的路徑如下:
C:\Users\JackPi\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets
其中JackPi為使用者名稱稱。如果沒有發現AppData,在JackPi目錄下,把隱藏的檔案取消,即可檢視。然而原始檔是一系列沒有檔案字尾的字串,為檔案新增**".jpg"**字尾,圖片就可以查看了。於是就想著使用python去批量修改檔名稱。
學習python加python程式語言學習扣群
程式程式碼
1,import os
2,import datetime
3,#切換路徑
4,os.chdir("source")
5,#獲取時間物件
6,currTime=datetime.datetime.now()
7,#設定修改後的名稱
8fileNewName="{0}{1}{2}".format(currTime.year,currTime.month,currTime.day)
9,i=010,for file in os.listdir():
11, #開始修改檔名稱
12,os.rename(file,fileNewName+str(i)+".jpg")
13,i+=1
說明
原始檔如下圖所示:
檔案修改後結果如圖:
需要說明的是:
這裡我把原始檔放在soruce資料夾下,python程式與source在同一級。
學習python加python程式語言學習扣群 5152+67276