我在 Windows 中创建批处理文件并将其添加到上下文菜单中,以便通过右键单击菜单运行脚本。
批处理文件如下所示:
@echo off
cwebp.exe -q 100 -m 6 -mt -af -progress -short %1 -o %~n1.webp
如果文件名中没有空格,脚本就可以正常工作。
例如:LogoBlack.png
问题是,如果文件名中有空格,脚本就无法运行。
例如:Logo Black.png
错误cwebp.exe
返回此消息:
Converting file D:\Kashif\images\AMG Logo Black.png SHCreateStreamOnFile((const LPTSTR)filename, > STGM_READ, stream) failed 80070002 Error opening input file Black.webp (80070002) OpenInputStream(filename, &stream) failed 80070002 cannot open input file 'Black.webp' Error! Could not process file Black.webp Error! Cannot read input picture file 'Black.webp'
答案1
@echo off
set "_cwebp=%UserProfile%\Downloads\libwebp-1.2.0-windows-x64\bin\cwebp.exe"
timeout 5 | 2>&1 "%_cwebp%" -q 100 -m 6 -mt -af -progress -short "%~f1" -o "%~dpn1.webp"
观察:ATimeout 5
它的作用是方便拖放操作,并允许读取发生的错误返回值,以及执行
@echo off
set "_cwebp=%UserProfile%\Downloads\libwebp-1.2.0-windows-x64\bin\cwebp.exe"
timeout 5 | 2>&1 "%ComSpec%" /v:off /e:off /s /c ^"call "%_cwebp%" -q 100 -m 6 -mt -af -progress -short "%~fs1" -o "%~dpn1.webp"^"