判断一下文件名,防止多次累加目录名- ::添加目录名前缀
- @echo off
- cd/d%~dp0
- setlocal enableDelayedExpansion
- for /f "delims=" %%d in ('dir/s/b/ad')do (
- pushd %%d
- call :strLen dLen "%%~nxd"
- for /f "delims=" %%f in ('dir/b/a-d')do (
- set "filename=%%f"
- for /f %%s in ("!dlen!")do if "!filename:~,%%s!" neq "%%~nxd" ren "%%f" "%%~nxd%%f"
- )
- popd
- )
- pause
- goto :eof
-
- :strLen len str ::code by plp626
- setlocal
- set "$=%~2#"
- set N=&for %%a in (4096 2048 1024 512 256 128 64 32 16)do if !$:~%%a!. NEQ . set/aN+=%%a&set $=!$:~%%a!
- set $=!$!fedcba9876543210&set/aN+=0x!$:~16,1!
- endlocal&set/a%1=%N%
- goto :eof
复制代码
|