批处理按txt列表重命名文件bat代码?

例如:
文件名为:
张三
李四
王五
麻六

txt列表为
zhangsan
lisi
wangwu
maliu

不清楚你的实际文件/情况,仅以问题中的样例说明及猜测为据;以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI,跟要处理的文件放一起双击运行
<# :
cls
@echo off
rem 将当前目录里的多个文件按照原有排序分别重命名为不同名称
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
#>
$namelist=@"
lisi
zhangsan
maliu
wangwu
"@;
$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;
$arr=$namelist.trim() -split '[\r\n]+';
[byte[]]$b=@(32,45,45,62,32);
$c=[Text.Encoding]::Default.GetString($b);
$self=get-item -liter $args[0];
$path=$self.Directory.FullName;
$files=@(dir -liter $path|?{($self.Name -ne $_.Name) -and ($_ -is [System.IO.FileInfo])}|%{$_.Name});
if($files.length -ge 1){
$brr=[ExpDir]::Sort($files);
for($i=0;$i -lt $brr.length;$i++){
$f=get-item -liter $brr[$i];
if($i -lt $arr.length){
$newname=$arr[$i]+$f.Extension;
$brr[$i]+$c+$newname;};};}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2020-12-09
重命名需要两个参数,一个是原名,一个是新名
txt里需要两列本回答被网友采纳
相似回答