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?

phuclv
  • 37,963
  • 15
  • 156
  • 475
joehua
  • 725
  • 3
  • 10
  • 25

1 Answers1

0

Give this a burl. If it echo's the right rename command then remove the echo and the pause to activate it. It's untested. Paths containing ! and % characters will cause an issue.

@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
        )
     )
)
foxidrive
  • 40,353
  • 10
  • 53
  • 68