Is there a way to put multiple actions under a if condition? Like this:
if not exist MyFolderName (
ECHO create a folder
mkdir MyFolderName
)
Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.
You can use batch scripts to run multiple commands and instructions on your machine simultaneously. Using a batch script, you will be able to execute all your commands one by one automatically.
When used in a command line, script, or batch file, %1 is used to represent a variable or matched string. For example, in a Microsoft batch file, %1 can print what is entered after the batch file name.
In the batch script, you can get the value of any argument using a % followed by its numerical position on the command line. The first item passed is always %1 the second item is always %2 and so on. If you require all arguments, then you can simply use %* in a batch script.
You can use &
to join commands and execute them on the same line.
So your syntax should look like:
if not exist MyFolderName ECHO "Create a folder" & mkdir MyFolderName
UPDATE
Or you can use labels to jump to a section containing the commands you want to execute, for example:
if not exist MyFolderName GOTO DOFILESTUFF
:AFTER
...
EXIT
:DOFILESTUFF
ECHO "Create a folder"
mkdir MyFolderName
GOTO AFTER
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With