| The Code for: "CheckForMissingDirectoryUpdateDescEnvVarIfSo.cmd.txt" |
This is the example, a shortcut was installed to this code :
@echo off ::@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ :: $Header: C:/DBAREIS/Projects.PVCS/Win32/ScriptingTipsAndTricks/EXAMPLE[cmd].CheckForMissingDirectoryUpdateDescEnvVarIfSo.cmd.txt.pvcs 1.0 29 Jun 2014 12:51:20 USER "Dennis" $ ::@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ setlocal set CrcDir=C:\tmp\x\y\z if not "%CrcDir%" == "" call :CheckForMissingDirectoryUpdateDescEnvVarIfSo "%CrcDir%" if "%Desc%" == "" goto RootDirectoryExists call :SAY ERROR: The directory "%CrcDir%" doesn't exist :-( goto :EOF :RootDirectoryExists call :SAY ERROR: The directory "%CrcDir%" exists :-) goto :EOF ::**************************************************** :CheckForMissingDirectoryUpdateDescEnvVarIfSo ::**************************************************** set StartingDir=%~1 set LookAtDir=%StartingDir% set PrevLookAt= :WorkDownTree call :SAY Looking at directory: "%LookAtDir%" if exist "%LookAtDir%\." goto FoundDir set PrevLookAt=%LookAtDir% ::--- If network too slow to check further -------------------------- if "%LookAtDir:~0,2%" == "\\" echo Won't work down tree on network drives& goto EndOfDirTree ::--- Not found, lets see if at C$ or C: root ------------------------ set LastChar=%LookAtDir:~-1% ::echo LastChar = "%LastChar%" / PrevLookAt = "%PrevLookAt%" if "%LastChar%" == ":" goto EndOfDirTree if "%LastChar%" == "$" goto EndOfDirTree ::--- Directory not found, lets see how far the problem goes --------- set LookAtDir= for %%x in ("%PrevLookAt%") do set LookAtDir=%%~dpx if "%LookAtDir%" == "" goto EndOfDirTree set LookAtDir=%LookAtDir:~0,-1% if "%LookAtDir%" == "" goto EndOfDirTree ::--- Play safe and cover mistakes causing infinite loops ---------- if "%LookAtDir%" == "%PrevLookAt%" goto EndOfDirTree goto WorkDownTree :FoundDir call :SAY FOUND FOLDER : "%LookAtDir%" if "%StartingDir%" == "%LookAtDir%" goto :EOF ::--- Definately missing --------------------------------------------- :EndOfDirTree if "%StartingDir%" == "%PrevLookAt%" set Desc=MISSING if not "%StartingDir%" == "%PrevLookAt%" set Desc=MISSING@'%PrevLookAt%' goto :EOF
Please note that that I am not trying to show how great I am by producing batch files 9,000 characters long on one line that no one will understand or be able to debug when they go wrong. I am going out of my way to comment the code and make it verbose so beginners and advanced users will both benefit. I don't claim to be an expert that knows everything, if I'm wrong or make a mistake then please contact me and let me know :-)
![]() | ![]() |