- <# :
- cls&echo off&cd /d "%~dp0"&mode con lines=5000
- powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal '%~f0'|Out-String|Invoke-Expression"
- pause
- exit
- #>
- $folder=@(
- ".\111\222"
- );
-
- for($i=0;$i -lt $folder.length;$i++){
- if(test-path -literal $folder[$i]){
- $files=@(dir -literal $folder[$i] -recurse|sort {$_.FullName.length} -Descending);
- for($j=0;$j -lt $files.length;$j++){
- $fn=$files[$j].Name -replace ' ','';
- $base=$files[$j].BaseName -replace ' ','';
- $filepath=$files[$j].FullName -replace '\\[^\\]+$','';
- if($fn -ne $files[$j].Name){
- $newname=$fn;
- $newfile=$filepath+'\'+$newname;
- $n=2;
- while(test-path -literal $newfile){
- $newname=$fn+'('+$n.ToString()+')';
- if($files[$j] -is [System.IO.FileInfo]){
- $newname=$base+'('+$n.ToString()+')'+$files[$j].Extension;
- }
- $newfile=$filepath+'\'+$newname;
- $n++;
- }
- write-host ($files[$j].FullName+' --> '+$newname);
- rename-item -literal $files[$j].FullName $newname;
- }
- }
- }else{write-host ('"'+$folder[$i]+'" Not Found')}
- }
复制代码
|