问题
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
回答1:
This works here.
@ECHO OFF
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /D /R %%i IN (*) DO (
SET "n=%%~nxi"
REN "%%i" "!n: =-!"
)
回答2:
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.
来源:https://stackoverflow.com/questions/19251407/how-to-replace-spaces-with-dashes-of-folder-names-in-bulk