DOS .bat files (What I learned from writing a subversion backup script)

Comments
REM Comment Style 1
:: Comment Style 2

Set a variable
SET myCat=Dante
Output a variable
ECHO %myCat%
If then Else statement
if %yCat%== "Dante" (ECHO MY CAT) ELSE (ECHO NOT MY CAT)
Output a command’s result to a file
dir >> log.txt
Split a command across 2 lines (use ^ at the end of the line)
ECHO This is line one and ^
this is line 2.

Two commands on 1 line (separate with &)
echo command 1 & echo command2
List only directory names and no info
dir /b /ad
For-in-do (For every item do something)
FOR /F %%G IN ('dir /b /ad %repodir%') DO ECHO %%G

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.