Thursday, November 9, 2017

Replace "space" with"underscore" in folder name - recursively

I have multiple folders with space in the folder name, and need to replace the space with underscore.
Found a simple batch file to do that

From this:


To this:


Script:
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION

FOR /D %%d IN (*) DO (
   SET "NAME=%%d"
   SET "NEWNAME=!NAME: =_!"
   IF NOT "!NAME!"=="!NEWNAME!" rename "!NAME!" "!NEWNAME!"
)
pause
exit


No comments:

Post a Comment