Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.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
Command line 如何在批处理文件中生成OR语句?_Command Line_Batch File_Cmd_Command Prompt_Sqlcmd - Fatal编程技术网

Command line 如何在批处理文件中生成OR语句?

Command line 如何在批处理文件中生成OR语句?,command-line,batch-file,cmd,command-prompt,sqlcmd,Command Line,Batch File,Cmd,Command Prompt,Sqlcmd,希望从我的批处理文件中排除2个或多个文件 我的批处理文件执行该文件夹中的所有SQL文件 代码如下: ECHO %USERNAME% started the batch process at %TIME% >output.txt FOR %%G IN (*.sql) DO ( //IF would go here to skip unwanted files sqlcmd.exe -S RMSDEV7 -E -d ChaseDataMedia7 -i "%%G" >>o

希望从我的批处理文件中排除2个或多个文件

我的批处理文件执行该文件夹中的所有
SQL
文件

代码如下:

ECHO %USERNAME% started the batch process at %TIME% >output.txt 

FOR %%G IN (*.sql) DO (
//IF would go here to skip unwanted files
sqlcmd.exe  -S RMSDEV7 -E   -d ChaseDataMedia7 -i "%%G" >>output.txt
)

pause
那么,我如何添加和if statement以跳过循环中我不想执行的文件呢?

您可以链接if

FOR %%G IN (*.sql) DO (
   if not %%G==foo.sql if not %%G==bar.sql (
      some command "%%G"
   )
)

获取一个名称并通过删除当前名称来复制UnwantedFile。如果结果与以前相同,则此名称不在UnwantedFile中,因此请处理它…

Q&D,但另一个选项可能是在循环之前重命名这两个文件,然后再还原它们。@Lieven可行,但我不想一天删除和还原20次,希望其他开发人员只运行批处理文件。无需担心删除和恢复。的可能重复
@echo off
setlocal EnableDelayedExpansion
set unwantedFiles=foo bar baz
for %%g in (*.sql) do (
   set "test=!unwantedFiles:%%~Ng=!"
   if "!test!" == "!unwantedFiles!" (
      echo %%~Ng.sql is not unwanted, process it:
      echo Process with %%g
   )
)