说明
锁屏界面Windows10聚焦所产生的图片很多都是著名摄影作品,很好看,但是Windows并不能将其设置为桌面壁纸,所以需要手动找到其保存位置,修改文件后缀名为jpg就可以保存为图片了,但是这样很麻烦,时间久了再好看的图片也会看腻,写一个脚本用来及时更新图片。
内容
脚本分为两个部分,一个run.bat批处理文件,仅有两行代码,另一个是get_wallpaper.py的Python脚本,是核心代码。
源码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
| '''
@Email: rumosky@163.com
@Author: rumosky
@Gitee: https://gitee.com/rumosky_admin
@Date: 2019-10-16 17:11:17
@Description: 一键获取Windows聚焦壁纸并保存为jpg图片脚本
'''
import os
import shutil
source = r"C:\Users\rumosky\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets"
destination = r"D:\wallpaper"
def get_path(dir):
for root, dirs, files in os.walk(dir):
pass
return root, files
pass
def get_destination_jpg(dir):
root, files = get_path(destination)
destination_jpg = []
for file in files:
if(file[-3:] == 'jpg'):
destination_jpg.append(file)
pass
pass
return destination_jpg
pass
def find_new_jpg():
des = get_destination_jpg(destination)
r, source_files = get_path(source)
new_jpg = []
count = 0
for source_file in source_files:
if source_file+".jpg" not in des:
count = count+1
new_jpg.append(source_file)
pass
pass
return count, new_jpg
pass
def copy():
count, new_jpg = find_new_jpg()
if count > 0:
for jpg_file in new_jpg:
source_path = source+'\\'+jpg_file
destination_path = destination+'\\'+jpg_file+'.jpg'
shutil.copyfile(source_path, destination_path)
pass
pass
return count, new_jpg
pass
if __name__ == "__main__":
count, without = copy()
new_jpg = []
print("更新了 "+str(count)+" 张图片")
for new_jpg in without:
print(new_jpg+".jpg")
pass
pass
|
source后的路径就是Windows10聚焦文件保存的位置,注意修改Users后面的用户名为自己的
destination是图片存放的位置,必须提前建立好该文件夹,否则会出错
run.bat
1
2
3
| python get_wallpaper.py
pause
|
run.bat可以不用,只需要电脑上有能运行Python脚本的软件即可,run一下get_wallpaper.py就行
结果
运行一下run.bat,结果如图:

大功告成!