如何将“IF FOR batch”与“FOR DELIMS batch”连接起来?

如何将“IF FOR batch”与“FOR DELIMS batch”连接起来?

这是我的脚本的第一部分:

@echo off
cd /D "E:\[0] EE\feed\"
if exist "*.ss" (
if not exist "O.ss" (
    FOR %%A IN (*.ss) DO (
        IF /I NOT "%%~A"=="O2.ss" REN "%%~A" "O.ss" > nul 2>&1
    )))
pause

这是我的脚本的第二部分:

@Echo off & SetLocal EnableExtensions EnableDelayedExpansion
Set "Video="
for /f "delims=" %%a in ('findstr /i "^Video=" job1.ini') do set "%%a"
"C:\Temp\mkvmerge.exe" -o "E:\done.mkv" --title "B 1" "%Video%" "C:\Temp\audio.flac"
pause

如果我单独运行它们,它们将按预期执行,但是当我像这样将它们连接起来时:

@Echo off & SetLocal EnableExtensions EnableDelayedExpansion 
cd /D "E:\[0] EE\feed\" 
if exist "*.ss" ( 
if not exist "O.ss" (
    FOR %%A IN (*.ss) DO (
        IF /I NOT "%%~A"=="O2.ss" REN "%%~A" "O.ss" > nul 2>&1
    ))) 
Set "Video=" 
for /f "delims=" %%a in ('findstr /i "^Video=" job1.ini') do set "%%a" 
"C:\Temp\mkvmerge.exe" -o "E:\done.mkv" --title "B 1" "%Video%" "C:\Temp\audio.flac" 
pause

我收到错误:

findstr:无法打开 job1.ini

我想是因为我有%%A在这些 IF 语句中?

有什么办法可以解决这个问题吗?

答案1

你可以尝试这个:

@Echo off & SetLocal EnableExtensions EnableDelayedExpansion 
PushD "E:\[0] EE\feed\" 
if exist "*.ss" ( 
if not exist "O.ss" (
    FOR %%A IN (*.ss) DO (
        IF /I NOT "%%~A"=="O2.ss" REN "%%~A" "O.ss" > nul 2>&1
    )))
PopD 
Set "Video=" 
for /f "delims=" %%a in ('findstr /i "^Video=" job1.ini') do set "%%a" 
"C:\Temp\mkvmerge.exe" -o "E:\done.mkv" --title "B 1" "%Video%" "C:\Temp\audio.flac" 
pause

在第一部分中,您将目录从批处理和大概也是 job1.ini 所在的文件夹更改了。
PushD工作原理类似cd /d,但将旧位置存储在内部堆栈上并PopD恢复保存的位置。

相关内容