[英]Remove Prefix from all file in current folder as well as files in subfolder windows batch
i am trying to remove prefix from all files in current folder and subfolders i tryed following code which work only for current folder 我正在尝试从当前文件夹和子文件夹中的所有文件中删除前缀,我尝试了以下仅对当前文件夹有效的代码
setlocal enabledelayedexpansion
for %%F in (*) do (
set "FN=%%F"
set "FN=!FN:~15!"
ren "%%F" "!FN!"
)
goto :eof
Please Help me to solve this 请帮我解决这个问题
for /f "delims=" %%a in ('dir /b /a-d /s') do (
set "fname=%%~nxa"
set "fpath=%%~dpa"
setlocal enabledelayedexpansion
set "nname=!fname:~15!"
ren "!fpath!!fname!" "!nname!"
endlocal
)
This is the safe way to preserve exclamation marks. 这是保留感叹号的安全方法。
If you are using windows 7, you could try this: 如果您使用的是Windows 7,则可以尝试以下操作:
forfiles /s /c "cmd /c ren @file @fname"
It took me a bit of time to find, but suddenly I realised that the batch file was not working because it had renamed itself!. 我花了一些时间才找到,但是突然我意识到该批处理文件由于重命名了而无法正常工作。
If this becomes an issue you could try naming the batch file zzzzzzzzz.bat
which I think would prevent it from renaming itself first. 如果这成为问题,您可以尝试命名批处理文件
zzzzzzzzz.bat
,我认为这将阻止它首先重命名自己。
Mona 莫娜
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.