How to make an OR statement in a batch file?

Hi, I want to exclude 2 or more files from my batch file.

My batch file executes all the SQL files in this folder.

Here is the code:

 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 

So, how would I add and if statemant skip files in a loop that I don't want to execute?

+4
source share
2 answers

You can bind IFs;

 FOR %%G IN (*.sql) DO ( if not %%G==foo.sql if not %%G==bar.sql ( some command "%%G" ) ) 
+4
source
 @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 ) ) 

Take a name and copy unnecessary files by deleting the current name. If the result is the same as before, this name is NOT in the unwanted files, so process it ...

+2
source

Source: https://habr.com/ru/post/1390808/


All Articles