shhz

Windows聚焦锁屏界面的图片想保存下来,但是图片没有扩展名,需要自己手动改成.png格式

并且Assets目录会被Windows自动清理,所以写了个Powershell脚本来保存图片到别的目录

图片有两种分辨率1920*1080和1080*1920,我用图片高做了判断分别放在两个文件夹中

 

脚本名称:savepic.ps1

cmd中执行脚本

E:\> powershell -file E:\脚本\savepic.ps1

 

Powershell中执行脚本

PS E:\> .\savepic.ps1

 

可以创建快捷方式,自己点一下就完成

或者创建计划任务,自动完成保存图片

 

[system.reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
$filelist = ls "$env:userprofile\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets\"

foreach($file in $filelist){
  $filename = $file.name
  $fullname = $file.FullName
  $img = [System.Drawing.Image]::FromFile($fullname)

  if($img.height -eq 1080){ ## IPP 1920*1080
    $fileipp = Test-Path "$env:userprofile\Pictures\iPP\$filename.png"    
    if($fileipp -eq $false){
      copy $fullname "$env:userprofile\Pictures\iPP\$filename.png"
      #echo "copy $fullname to $env:userprofile\Pictures\iPP\$filename.png"
    }
  }
  else{                     ## IMP 1080*1920
    $fileimp = Test-Path "$env:userprofile\Pictures\iMP\$filename.png"
    if($fileimp -eq $false){
      copy $fullname "$env:userprofile\Pictures\iMP\$filename.png"
      #echo "copy $fullname to $env:userprofile\Pictures\iMP\$filename.png"
    }
  }
}

 

分类:

技术点:

相关文章: