本帖最后由 flashercs 于 2019-8-2 22:02 编辑
- @echo off
- REM 功能:以%dri%为根目录,删除深度大于%depth%的目录中的文件名和文件夹名中字符串%str2replace%
- REM 要处理的目录深度是大于%depth%,根目录深度是0,依次递增。
- REM depth : 要操作的目录深度必须大于 depth
- set "depth=0"
- REM 根目录,默认是脚本所在目录
- set "dir=%~1"
- REM 文件或目录名中需要删除的字符串
- set "str2replace=来阁设计整理出品-"
- if not defined dir set "dir=%~dp0"
- call :recurse "%dir%" 0
- pause
- exit /b
- :recurse
- setlocal
- pushd %1||goto end
- set /a "childdepth=%2+1"
- REM 处理当前目录的文件夹,centerorder
- for /f "delims=" %%A in ('"2>nul,dir /ad /b"') do (
- call :recurse "%%A" %childdepth%
- if %2 gtr %depth% (
- echo Directory: "%%~fA"
- set "fsoname=%%A"
- call ren "%%A" "%%fsoname:%str2replace%=%%"
- )
- )
- if %2 leq %depth% goto out
- REM 处理当前目录的文件,postorder
- for /f "delims=" %%B in ('"2>nul,where ".:*%str2replace%*""') do (
- echo File: "%%B"
- set "fsoname=%%~nxB"
- call ren "%%fsoname%%" "%%fsoname:%str2replace%=%%"
- )
-
- :out
- popd
- :end
- endlocal
- exit /b
复制代码
|