Here is an example showing batch file commands in action
connect http://localhost/reportserver
@echo off
rem clear the screen
cls
rem ========================================================
rem this test shows the batch file processing for a script
rem folder management and if exists and if not exists commands.
rem note the exists command can be used with a goto statement or another command.
rem ========================================================
rem test folder commands. remove, add, change directory
rem ========================================================
rem set the start folder for test
cd\
echo delete folder \ssrstest
rd \ssrstest /q /s
rem ========================================================
rem check the folder is deleted
rem ========================================================
if not exists "\ssrstest" goto Test1success
echo \ssrstest folder deleted
goto errFolderNotDeleted
:Test1success
rem ========================================================
rem here is an example to check a folder does not exist and echo a message saying it does not exist
rem ========================================================
if not exists "\ssrstest" echo the folder \ssrstest does not exist- as we have just deleted it!
rem ========================================================
rem create the folder
rem ========================================================
md \ssrstest
If exists "ssrstest" goto test2
echo Test1 failed
goto fail
echo Test1 passed
:test2
rem ========================================================
rem test2 create sub folder from a directory other than root
rem ========================================================
rem change directory to \ssrstest
cd \ssrstest
rem ========================================================
rem create a subfolder under ssrstest (relative folder)
rem ========================================================
md subfolderRel
rem ========================================================
rem check the folder exists
rem note the file/folder must be in quotes.
rem this checks for the absolute folder exists.
rem ========================================================
If exists "\ssrstest\subfolderRel" goto test2apass
echo Test2 relative folder failed
goto fail
rem ========================================================
rem check the folder exists
rem note the file/folder must be in quotes.
rem this checks for the absolute folder exists.
rem ========================================================
If exists "subfolderRel" goto test2apass
echo Test2relative folder check failed
goto fail
:test2apass
rem ========================================================
rem create a subfolder with spaces in name under ssrstest (absolute folder)- NOTE '\' in the folder name..
rem ========================================================
md "\ssrstest\subfolderAbs Space"
rem now goto the folder "\ssrstest\subfolderAbs Space"
cd \ssrstest\subfolderAbs Space
echo show the current folder use the cd command
cd
rem ========================================================
rem create another folder under ssrstest (relative folder)
rem we are currently in the folder \ssrstest
rem the process is to use ..\ to go back a folder level
rem ========================================================
md "..\subfolderRel New"
rem check the folder exists
If exists "\ssrstest\subfolderAbs Space" goto test2bpass
echo Test2 relative folder failed
goto fail
:test2bpass
goto success
rem ===========================
rem summary
rem ===========================
:fail
echo there were errors
goto end
:errFolderNotDeleted
echo error folder not deleted
goto end
:success
echo All tests passed- there were no errors
cd\
goto end
:end