不清楚你的实际文件/情况,仅以问题中的样例/说明为据;以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI,跟要处理的文件放一起运行
<# :
cls
@echo off
rem 按当前目录下文件原有的排序,将多个.ass文件一一对应重命名成与.mkv文件相同名称
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
#>
$self=get-item -liter $args[0];
$path=$self.Directory.FullName;
$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;
$fs1=@(dir -liter $path|?{('.mkv' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])}|%{$_.Name});
$fs2=@(dir -liter $path|?{('.ass' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])}|%{$_.Name});
$arr=[ExpDir]::Sort($fs1);$brr=[ExpDir]::Sort($fs2);
for($i=0;$i -lt $arr.count;$i++){
if($brr.count -le $arr.count){
$mkvfile=get-item -liter ($path+'\'+$arr[$i]);
$assfile=get-item -liter ($path+'\'+$brr[$i]);
$assnewname=$mkvfile.BaseName+$assfile.Extension;
write-host ($brr[$i]+' --> '+$assnewname);
};
}
追问您的脚本看起来非常高端,可惜我没能运行成功,双击运行之后并没有修改文件名,不过图片上看起来已经很接近了。如果在命令提示符下运行这个bat提示The syntax of the command is incorrect.
![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/0e2442a7d933c89564f68805c11373f0830200c7?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)
追答按运行代码后窗口标题栏中的提示联系我