求助大神bat批量重命名指定路径下的文件名

比如D盘下有A.B.C三个文件夹 ABC文件夹里面有很多照片 想把照片分别重命名为A1 A2.... B1 B2... C1 C2.... 半夜打扰 不甚感激

不清楚你的实际文件/情况,仅以问题中的样例说明及猜测为据;以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI,跟要处理的多个文件夹放一起双击运行<# :
cls&echo off&cd /d "%~dp0"&mode con lines=5000
rem 将当前目录下多个子文件夹里的文件,分别以其所在子文件夹的名称和递增序号重命名
set #=Any question&set _=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%_% %z%
set "current=%cd%"
powershell -NoProfile -ExecutionPolicy bypass "Get-Content -literal '%~f0'|Out-String|Invoke-Expression"
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;

$b=[Convert]::FromBase64String("IC0tPiA=");
$c=[Text.Encoding]::Default.GetString($b);
$current=$env:current;
$folders=@(dir -literal $current|?{$_ -is [System.IO.DirectoryInfo]});
for($i=0;$i -lt $folders.length;$i++){
    $files=@(dir -literal $folders[$i].FullName|?{$_ -is [System.IO.FileInfo]}|%{$_.Name});
    if($files.length -ge 1){
        write-host $folders[$i].FullName -ForegroundColor yellow;
        $arr=[ExpDir]::Sort($files);
        for($j=0;$j -lt $arr.Count;$j++){
            $ext='';
            $m=[regex]::match($arr[$j], '\.[^\.]+$');
            if($m.Success){$ext=$m.groups[0].value;}
            $newname=$folders[$i].Name+'_'+($j+1).ToString()+$ext;
            $arr[$j]+$c+$newname;
        }
        write-host '';
    }
}

温馨提示:答案为网友推荐,仅供参考
相似回答