How to replace spaces with dashes of folder names (in bulk) [closed]

狂风中的少年 提交于 2019-12-26 07:43:43

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!