0

I would like to rename directories whose name contains the word "NOTE", but not "NOTES", to "NOTES". I first experiment with the echo command.

for /f "tokens=1-7"  %%i in ('dir d:\mydirectory /s /b /ad ^|find "NOTE" ^|find "NOTES" /v') do @echo %%i %%j %%k %%l %%m %%n %%oS

Because directory names have different spaces in them, the above command may leave spaces between "NOTE" and S. Anyway to overcome this problem?

4

1 回答 1

0

给这个树瘤。如果它回显是正确的重命名命令,则删除echopause激活它。它未经测试。!包含和字符的路径%将导致问题。

@echo off
setlocal enabledelayedexpansion
for /d /r %%a in (*) do (
  set "f=%%~nxa"
     if not "!f:NOTE=!"=="%%~nxa" (
        if "!f:NOTES=!"=="%%~nxa" (
           echo ren "%%a" "!f:NOTE=NOTES!"
           pause
        )
     )
)
于 2013-08-11T07:00:01.303 回答