Saturday
Sep302006
Batch Snippets
Saturday, September 30, 2006 at 06:10PM
To obtain the path of the batch file which is currently executing!
echo %~dp0
echo %~dp0
A simpler way to comment!
@rem This is an ugly comment.
:: This is also a comment!
@rem This is an ugly comment. :: This is also a comment!
Prompt the user for a string!
@SET /p FolderName=What do you want the subdir folder to be called? (No Spaces!):
@SET /p FolderName=What do you want the subdir folder to be called? (No Spaces!):
Create a timestamp with Date and Time with a underscore seperating them.
set DateStamp=%DATE:~10,4%%DATE:~4,2%%DATE:~7,2% set TimeStamp=%TIME::=% set TimeStamp=%DateStamp%_%TimeStamp:.=% set TimeStamp=%TimeStamp: =0% echo %TimeStamp% :: TimeStamp is like 20120326_13034087
Tests to see if an svn export was successful. This snippet could be applied to a lot of situations where you want to test if a command was successful.
svn export <REPO_URL> C:\path\to\outputdir --username <USERNAME> --password <PASS> --non-interactive set svnErrorLevel=%ERRORLEVEL% IF NOT %svnErrorLevel% == "0" GOTO FAILED rem PUT STUFF HERE THAT SHOULD EXECUTE ONLY IF EXPORT WAS SUCCESSFUL GOTO end :FAILED
How to test to see if an argument is set. (Notes: 1) there must be quotes around the %1 and 2) the goto
if "%1" == "" goto displayUsageNOTE: I asked a question about this on stackover flow and got a good answer that works even when you have variables that might have quote in it. Google blak3r on stackoverflow + batch test and you’ll probably find it.
Add a user definable delay, where the number following -n is number of seconds
ping -n 2 1.1.1.1 > NUL
Reader Comments