Python3获取Win10精美锁屏壁纸(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()