I suggest first to read Single line with multiple commands using Windows batch file explaining the operators &
and &&
and ||
which can be used in a batch file or on Windows command prompt.
The right command line with multiple commands for this example is:
cd \ & mkdir "C:\Users\Admin\Documents\test" 2>nul
The first command cd \
sets current directory to root of current drive although this is not really necessary.
The second command "C:\Users\Admin\Documents\test" 2>nul
creates the entire directory tree (with enabled command extensions as by default). If an error occurs like this directory already existing, the exit code of command MKDIR is 1
for failure instead of 0
for success. The error message is redirected with 2>nul
from handle STDERR to device NUL to suppress it.
It is of course also possible that the directory could not be created because the used user account does not have permissions to create this directory or there is in directory C:\Users\Admin\Documents
already a file with name test
. For that reason it is perhaps better to use:
cd \ & ( if not exist "C:\Users\Admin\Documents\test\" mkdir "C:\Users\Admin\Documents\test" 2>nul ) & echo OK
More commands can be appended with &
, &&
or ||
as demonstrated here with echo OK
being always executed independent on IF condition and result of creation of the directory.