Windows 10下如果將鎖屏界面設置成Windows聚焦時,在每次鎖屏后都會推送不同的鎖屏圖片,有很多都是優秀的攝影作品,利用Python我們可以將其自動存儲到本地。
圖片位置
首先我們需要指定鎖屏圖片存在什么位置,百度一下,你就知道Windows 10的鎖屏壁紙在C:\Users\XXX\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets
的文件夾下。
“XXX”是個人的用戶名,而Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy
這個文件夾的名字也是隨機的,但Microsoft.Windows.ContentDeliveryManager_
的前綴不會變,只要找到這個前綴對應的文件夾即可。
找到該文件夾后我們發現,里面的文件都是沒有后綴名的,我們需要將后綴名改為.jpg
來查看。
自動重命名和存儲到自定義文件夾
利用Python 的文件操作,我們可以實現自動存儲功能。
代碼如下,功能較簡單,僅供參考:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import shutil
# 鎖屏畫報路徑,將xxx 替換為自己的user名稱,new_path 根據自己的需要進行更改
PATH = r"C:\Users\xxx" \
r"\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets\\"
NEW_PATH = r'C:\Users\xxx\Desktop\picture\\'
def rename_and_save_pic(file_path, new_path):
if not os.path.exists(new_path):
os.makedirs(new_path)
if os.path.exists(new_path):
i = len(os.listdir(path=new_path))
for file in os.listdir(path=file_path):
i += 1
shutil.copy(file_path+file, new_path+'picture_ %d' % i + '.jpg')
if __name__ == '__main__':
rename_and_save_pic(PATH, NEW_PATH)