I have the following lines in a batch file; @echo off if not exist "%userprofile%\desktop\Tools"\nul mkdir "%userprofile%\desktop\Tools" How do I suppress the following lines if the folder exists ? A subdirectory or file xxxxxxxxxx already exists.
It's how you pipe the output to the nul file. The following code works as expected: Code: @echo off set tools=%userprofile%\Desktop\Tools if not exist "%tools%" mkdir "%tools%" >> nul
If you like spaghetti you may also try this: Code: @echo off if exist "%userprofile%\desktop\Tools"\nul goto option1 if not exist "%userprofile%\desktop\Tools"\nul goto option2 :option1 (whatever) :option2 mkdir "%userprofile%\desktop\Tools"
Looks like you are always trying to create an existing directory. BTW output of mkdir cannot be suppressed by >nul
Nobody is piping or redirecting output, this old method of using \nul was used to identify the existence of a directory with command.com as the console. But like this: Code: IF NOT EXIST "%USERPROFILE%\DESKTOP\TOOLS\NUL" MKDIR "%USERPROFILE%\DESKTOP\Tools" I'd suggest this: Code: @ECHO OFF SETLOCAL (SET UDESK=%USERPROFILE%\DESKTOP) DIR /B /AD "%UDESK%\TOOLS" 1>NUL 2>&1 || MD "%UDESK%\TOOLS"