|
|
发表于 2026-7-10 14:52:46
|
显示全部楼层
本帖最后由 aloha20200628 于 2026-7-10 14:54 编辑
以下代码存为 test.bat 运行,自动检测无扩展名图片文件的真实类型(在4种常用类型 jpg, png, gif, bmp 中判断),结果复制为有扩展名的图片文件(新文件名取自当前时间)...
test.bat
- <# ::
- @echo off &setlocal &set "nf=%date:~,10%"
- set "pf=%APPDATA%\Microsoft\Windows\Themes\CachedFiles\TranscodedWallpaper"
- set "td=D:\Program Files (x86)\W-win10管理\P-屏保-壁纸\Wallpaper\win"
- set "nf=%nf:/=%_%time::=.%" &if not exist "%pf%" exit/b
- for /f %%x in ('powershell -nop -c "$pf='%pf%'; iex(${%~f0}|out-string)" ') do if "%%x" neq "0" copy /y "%pf%" "%td%\%nf%.%%x"
- exit/b
- #>
- $b=[io.File]::readAllBytes($pf)[0..7];$h=($b|%{$_.toString('X2')}) -join ''
- switch -wildcard ($h) { 'FFD8FF*' { 'jpg' }; '89504E47*' { 'png' }; '47494638*' { 'gif' }; '424D*' { 'bmp' }; default { '0' } }
- exit
复制代码 |
|