This example will loop only a set number of times, Also useful for counting the number of times a loop has run.
echo looped %counter% times
echo do something
if %counter% == 10 goto end
set /a counter=%counter% +1
echo Loop ran %counter% times
Filename friendly date, Sometimes you want to use the current date to generate a filename so can't use %date% as you normally get something like "Thu 16/05/2013". An easy way to reformat it to YYYYMMDD is as below.
echo and a sample file
echo %date% %time% >>%today%.log
Detect if Windows 32/64 bit. Some times you need to know if the script is running on a 32 bit or 64 bit version of Windows from the commandline. This allows the scripts to do different things depending upon the version of Windows.(Like use the "C:\Program Files (x86)\"path instead of "C:\Program Files\")
if defined ProgramFiles(x86) (
echo Is 64 bit version of windows
) else (
echo Is 32 bit version of windows