Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file IF语句中断批处理脚本_Batch File - Fatal编程技术网

Batch file IF语句中断批处理脚本

Batch file IF语句中断批处理脚本,batch-file,Batch File,我正在编写一个批处理脚本,以从其目录中提取视频文件。 到目前为止,它将进入与特定名称匹配的目录。然后,我对该目录中的每个项目执行FOR循环。我想检查一个项目是否是一个目录(我以前做过),如果是,则进入该目录,否则执行其他操作。 问题是第二个IF语句(用于检查项目是否为目录)正在破坏批处理脚本,并给出错误: )在这个时候是出人意料的 如果我删除该If,代码将按预期执行(我已清楚标记代码中的If语句) 代码: @ECHO off SET title=%1 SET mp4=".mp4" SET mk

我正在编写一个批处理脚本,以从其目录中提取视频文件。
到目前为止,它将进入与特定名称匹配的目录。然后,我对该目录中的每个项目执行
FOR
循环。我想检查一个项目是否是一个目录(我以前做过),如果是,则进入该目录,否则执行其他操作。

问题是第二个
IF
语句(用于检查项目是否为目录)正在破坏批处理脚本,并给出错误:

)在这个时候是出人意料的

如果我删除该
If
,代码将按预期执行(我已清楚标记代码中的
If
语句)

代码:

@ECHO off

SET title=%1
SET mp4=".mp4"
SET mkv=".mkv"
SET avi=".avi"
SET minimumSize=300
SET needCompressingDir="E:\Documents\Films\Need_compressing"

CD %needCompressingDir%
FOR /f "delims=" %%i IN ('DIR /B') DO (
    IF %%i == %title% (
        IF EXIST %%i (
            CD %%i
            FOR /f "delims=" %%j IN ('DIR /B') DO (
                rem this 'IF' statement breaks it
                IF EXIST %%j (

                ) ELSE (

                )
            )
        ) ELSE (
            MOVE %%i %needCompressingDir%
        )
    )
)

读取
如果/?

您可以看到,
命令
必需的部分,包括
if
else
部分。Windows
cmd
/
.bat
解释器不接受空命令块
()
:它不被视为命令。至少使用
REM
注释(无效命令):


已更新:使用
如果存在“%%~j\”
(注意后面的反斜杠)检查项目是否为目录。

读取
如果/?

您可以看到,
命令
必需的部分,包括
if
else
部分。Windows
cmd
/
.bat
解释器不接受空命令块
()
:它不被视为命令。至少使用
REM
注释(无效命令):


已更新:使用
如果存在“%%j\”
(注意后面的反斜杠)检查项目是否为目录。

%%j
返回的任何文件名是否包含空格?您应该尝试使用
if exist“%%j”
(以及
if exist“%%i”
)来代替。@SomethingDark是的,这完全可能发生,感谢您的洞察力,当我尝试使用
if exist“%%j”
时,我会尝试这种方法。
%%j
返回的任何文件名是否包含空格?您应该尝试使用
if exist“%%j”
(以及
if exist“%%i”
之前的用法)。@SomethingDark是的,这完全有可能发生,感谢您的洞察力,当我尝试使用
if exist”%%~j“
Performs conditional processing in batch programs.

IF [NOT] ERRORLEVEL number command
IF [NOT] string1==string2 command
IF [NOT] EXIST filename command
…
  command           Specifies the command to carry out if the condition is
                    met.  Command can be followed by ELSE command which
                    will execute the command after the ELSE keyword if the
                    specified condition is FALSE

The ELSE clause must occur on the same line as the command after the IF.  For
example:

    IF EXIST filename. (
        del filename.
    ) ELSE (
        echo filename. missing.
    )
        FOR /f "delims=" %%j IN ('DIR /B') DO (
            rem this 'IF' statement breaks it
            IF EXIST "%%~j\" (
              rem directory
            ) ELSE (
              rem not directory
            )
        )