不清楚你的实际文件/情况,仅以问题中的样例/说明为雀猜据;以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI,跟要处理的多个文件夹放一起运行
<# :
cls
@echo off
rem 将槐岁闷多个子文件夹里的文件按照资源管理器的原有排序/顺序分别以递增的数字序号重命名铅弯
mode con lines=3000
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]::Default))) -Args '%~f0'"
echo;%#% +%$%%$%/%@% %z%
pause
exit
#>
$codes=@'
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
public static class ExpDir
{
[DllImport("Shlwapi.dll", CharSet=CharSet.Unicode)]
public static extern int StrCmpLogicalW(string p1, string p2);
public static string[] Sort(string[] f)
{
Array.Sort(f, StrCmpLogicalW);
return f;
}
}
'@;
Add-Type -TypeDefinition $codes;
$self=get-item -liter $args[0];
$path=$self.Directory.FullName;
$folders=@(dir -liter $path|?{$_ -is [System.IO.DirectoryInfo]});
for($i=0;$i -lt $folders.length;$i++){
write-host $folders[$i].FullName;
$files=@(dir -liter $folders[$i].FullName|?{$_ -is [System.IO.FileInfo]}|%{$_.Name});
if($files.length -ge 1){
$list=[ExpDir]::Sort($files);
for($j=0;$j -lt $list.count;$j++){
$ext='';
$m=[regex]::match($list[$j], '\.[^\.]+$');
if($m.Success){$ext=$m.groups[0].value;};
$newname=($j+1).toString().PadLeft(3,'0')+$ext;
write-host ($list[$j]+' --> '+$newname);
};
};
}