我已经发现部分我的问题的解决方案这超级用户回答,但是我需要扩展代码以将文件命名为以下格式:<folder-name>+<user-defined-text>.iso
我迄今为止的代码:
for /r %%F in (*.iso) do @for %%A in ("%%F\..") do ren "%%F" "%%~nxA.iso"
答案1
尝试for /D /R
使用if exist files.iso
:
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
For /d /r
将检查所有子文件夹以查看其中是否有.iso
文件,如果有文件.iso
,则运行ren
(或移动)命令,通过将其添加到名称和变量中的字符串%custom%
(自定义文本 + .iso)来重命名该文件夹
- 在您的命令行中:
for /r /d %i in (*)do if exist "%~fi\*.iso" for /f tokens^=* %I in ('%__APPDIR__%where.exe "%~i:*.iso"')do ren "%~fI" "%~nxi_custom_name_here_%~xI"
- 在你的 bat/cmd 文件中:
@echo off & setlocal
cd /d "%~dp0" & set "_custom=_your_custom_name"
for /r /d %%i in (*)do if exist "%%~fi\*.iso" for /f tokens^=* %%I in (
'%__APPDIR__%where.exe "%%~i:*.iso"')do ren "%%~fI" "%%~nxi %_custom% %%~xI"
endlocal & goto :EOF