Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chain commands after "IF" Condtitional using &

I am trying to check if a folder has been created IF NOT create the folder

IF NOT EXIST dist\\js (MKDIR dist\\js)

then regardless if it did or did not create the folder i want to run

& uglifyjs dev/*.js -m -o dist/js/app.js

now it seems that the & is not working. The second command is not executed if the folder exists.

If i use the following as my first statement:

IF NOT EXIST dist\\js (MKDIR dist\\js) ELSE (Echo exist)

the first time around I run the two together as in:

IF NOT EXIST dist\\js (MKDIR dist\\js) ELSE (Echo hate) & echo Love & uglifyjs dev/*.js -m -o dist/js/app.js

The folder gets created BUT the app.js file is not created. Only when i run the command again it does create the app.js file.

Now how would i preferably check if theres a folder and then regardless continue with the next command.

like image 853
Timar Ivo Batis Avatar asked May 21 '26 17:05

Timar Ivo Batis


1 Answers

(IF NOT EXIST dist\\js (MKDIR dist\\js) ELSE (Echo hate)) & echo Love & uglifyjs dev/*.js -m -o dist/js/app.js

Parentheses enclose all the code before the & to make it operate as 1 complete condition. Once the condition is done, then the code after the & will execute regardless of the result of the previous condition.

The doubling up of backslashs are not needed for paths in batch-file as escapes such as \n for newline are not a part of the batch-file language.

like image 92
michael_heath Avatar answered May 23 '26 08:05

michael_heath