level 2
不清楚你的实际文件/情况,仅以问题中的样例/说明为据;以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI,跟要处理的多个文件夹放一起双击运行
<# :
cls&echo off&mode con lines=5000
rem 将当前目录里多个子文件夹内的一个xls表格文件用所在子文件夹名称中的数字部分来重命名
set #=Any question&set _=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%_% %z%
cd /d "%~dp0"
powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::GetEncoding('GB2312')))) -Args '%~f0'"
echo;%#% +%$%%$%/%_% %z%
pause
exit
#>
$self=get-item -liter $args[0];
$path=$self.Directory.FullName;
$b=[Convert]::FromBase64String("IC0tPiA=");
$c=[Text.Encoding]::Default.GetString($b);
$folders=@(dir -liter $path|?{$_ -is [System.IO.DirectoryInfo]});
for($i=0;$i -lt $folders.length;$i++){
$m=[regex]::match($folders[$i].Name, '\d+');
if($m.Success){
$files=@(dir -liter $folders[$i].FullName|?{(@('.xls','.xlsx') -contains $_.Extension) -and ($_ -is [System.IO.FileInfo])});
for($j=0;$j -lt $files.length;$j++){
$nname=$m.groups[0].value+$files[$j].Extension;
if($files[$j].Name -ne $nname){$files[$j].FullName.Substring($path.length)+$c+$nname;}
}}}
2021年10月10日 07点10分

