bat 循环语句可以双循环或者同步循环2个命令吗?

同一目录下有一堆mkv文件和一堆ass文件,需要把 dir *.ass的所有文件名按索引顺序改成和mkv同名。我的脚本有很多问题运行不了,麻烦大佬修改。
setlocal enabledelayedexpansion
set /a v=1
dir /b *.mkv >mkv.txt
for %%i in (*.ass) do call :aa !v!
:aa
for /f "delims=. tokens=%1" %%j in (mkv.txt) do echo %%j

set /a v+=1
echo !v!
goto :eof
del /f /q mkv.txt

不清楚你的实际文件/情况,仅以问题中的样例/说明为据;以下代码复制粘贴到记事本,另存为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.

追答

按运行代码后窗口标题栏中的提示联系我

温馨提示:答案为网友推荐,仅供参考
第1个回答  2020-09-15


写好了,自己撸吧:

@echo off &setlocal enabledelayedexpansion
dir /ad /b "C:\Release\ftp\up" >ftp.1st
for /f "delims=" %%c in (ftp.1st) do (
set Sum=0
for /l %%d in (1 1 3) do if exist "C:\Release\ftp\up\%%c\%%d.jpg" set /a Sum+=1
if !Sum! equ 3 start "C:\Release\ftp\bat\%%c.bat"
)
del /f /q ftp.1st &echo 运行结束! 
pause>nul





追问

大佬,麻烦看一看问题嘛。。。