Question

How to replace spaces with dashes of several thousand folders in bulk in Windows server 2008?.

Currently:

My folder

All folders need to become:

My-folder

Thanks

Was it helpful?

Solution

This works here.

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /D /R %%i IN (*) DO (
    SET "n=%%~nxi"
    REN "%%i" "!n: =-!"
)

OTHER TIPS

Use this batch file:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /D /R %%i IN (*.*) DO (
    SET "n=%%~nxi"
    SET n=!n: =-!
    IF NOT "!n!" == "%%~nxi" ECHO MOVE "%%~i" "%%~dpi!n!"
)

Check results and if everything looks OK, remove ECHO before MOVE.

EDIT: Interactive version:

@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
SET k=
FOR /D /R %%i IN (*.*) DO (
    SET "n=%%~nxi"
    SET n=!n: =-!
    IF NOT "!n!" == "%%~nxi" (
        ECHO "%%~i" =^> "!n!"
        IF /I NOT "!k!"=="A" SET /P k=[Y]es/[N]o/[A]ll]/[C]ancel?
        IF /I "!k!"=="C" GOTO :END
        IF /I "!k!"=="Y" MOVE "%%~i" "%%~dpi!n!"
        IF /I "!k!"=="A" MOVE "%%~i" "%%~dpi!n!"
    )
)
:END
PAUSE

Test this batch. It will ask before any rename (unless you enter A), so you can preview command and check result.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top