批处理 将文件夹内所有的文件名 生成文件夹名
发布网友
发布时间:2022-04-19 12:21
我来回答
共1个回答
热心网友
时间:2023-06-08 15:47
灞曞紑鍏ㄩ儴@echo off &setlocal enableDelayedExpansion
rem 璁剧疆婧愮洰褰?br />set "ScDir=D:\test"
cd /d "%ScDir%"
for /f "delims=" %%a in ('dir /a-d /s /b') do (
set "DirName=%%~dpa"
set "DirName=!DirName:~0,-1!"
if not defined $!DirName! (
set "$!DirName!=!DirName!"&set/a sum=1
) else (set/a sum+=1)
for /f "delims=" %%b in ("!DirName!") do set "DirName=%%~nb"
if !sum! LEQ 9 ( set "filename=!DirName!-0!sum!%%~xa" ) else ( set "filename=!DirName!-!sum!%%~xa" )
ren "%%a" "!filename!"
)
pause&exit