回复 9# ChenCheChe
重命名目录比较麻烦是因为一旦目录名改变了,那么该目录下的文件就找不到了,所以得用递归.
现在这脚本可以 替换文件名和目录名了.
以前的脚本就放弃吧.- REM 功能:替换文件名和目录名(包含子目录)的指定字符串
- @echo off
- set "dir=%~1"
- if not defined dir set "dir=%~dp0"
- REM 要替换的文件名字符串(可替换空格):
- set "strSrc=."
- REM 替换后的文件名字符串(删除则留空):
- set "strDst= "
- call :recurse "%dir%"
- pause
- exit /b %errorlevel%
-
- :recurse
- setlocal
- 2>nul,pushd %1||goto end
- REM 先处理文件-preorder
- for %%A in (*) do (
- if not "%%~fA"==%0 (
- call :renfso "%%A"
- )
- )
- REM 再处理目录-inorder
- for /d %%D in (*) do (
- call :recurse "%%D"
- call :renfso "%%D"
- )
- popd
- :end
- endlocal
- exit /b
-
- :renfso
- set "baseName=%~n1"
- call set "newBaseName=%%baseName:%strSrc%=%strDst%%%"
- if not "%newBaseName%"=="%baseName%" ren %1 "%newBaseName%%~x1"
- exit /b
复制代码
|