Windows10中的锁屏画面是每天自动更新的,那么遇到好看的照片就想保存下来,每天找到然后保存会比较麻烦,
于是写了个脚本把缓存中的图片拷贝到自定义背景的一个目录中,后面想着创建定时任务来完成移动锁屏画面。
以下是移动图片的脚本,主要用了Pillow,用来区分画面的比例。
import os
import shutil
from PIL import Image
path = 'C:/Users/faces/AppData/Local/Packages/Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy/LocalState/Assets'
dirs = os.listdir(path)
for filename in dirs:
file_path = os.path.join(path, filename)
size = os.path.getsize(file_path)
if size > 510000:
im = Image.open(file_path)
width, height = im.size
print('width:', width)
print('height:', height)
if width > height:
dstfile = os.path.join('D:\Windows\Screen', filename+'.png')
print(dstfile)
shutil.copyfile(file_path, dstfile)
创建定时任务用,这个命令需要使用管理员权限后输入
schtasks /create /F /ru Administrators /tn "Screen" /sc daily /st 10:00:00 /tr "C:\\Python36\\pythonw.exe D:\\work\\tools\\screen\\screen.py -task"