FOR /R %%a IN (poster.jpg) DO convert "%%a" -resize 256x256 -background none -gravity center -extent 256x256 "%%~dpna.ico"
当前行为是抓取每个 poster.jpg 文件并使用指定参数将其转换为 poster.ico。期望行为是还将其重命名以匹配文件夹名称。例如:输入:folder1\poster.jpg 输出:folder1\folder1.ico
答案1
您可以更换您的For /R
到For /R /D
您可以使用For /D /R
循环,它将遍历所有文件夹,并在循环内的每个文件夹中,使用条件if
检查您的poster.jpg
文件是否存在,如果返回 true,则运行您的命令。
for /r /d %%a in (*)do if exist "%~dpnxa\poster.jpg" convert "%%~a" -resize 256x256 -background none -gravity center -extent 256x256 "%%~dpa%%~na.ico"
FOR /R - Loop through files (recursively) FOR /D - Loop through several folders/directories
The option /D /R is undocumented, but can be a useful combination, while it will recurse through all subfolders the wildcard will only match against Folder/Directory names (not filenames) Note: Source linked to ss64.com
这是相同的逻辑/代码回答
进一步阅读: