Remarks or comments:

REM single line comments


By default, as a bash file runs each command will be echoed to the command prompt. This command turns that off:


Repeat plain text to STDOUT:

ECHO plain text

Echo a new-line character:



Set a variable:

SET variableName=value
Do not add whitespace around the equals sign.

Use a variable:

ECHO %variableName%


Copy a file:

COPY fromFile toFile

Move a file:

MOVE oldLocation newLocation
By default, the user will be prompted for permission to overwrite "newLocation". You can auto-accept the prompt:

MOVE /Y oldLocation newLocation

Append to file:

ECHO plain text >> toFile

Echo the contents of a file:

TYPE filename

Get path information from a full path:

set "filename=C:\Folder1\Folder2\File.ext"
FOR %%A IN ("%filename%") DO (
    ECHO full path: %%~fA
    ECHO directory: %%~dA
    ECHO path: %%~pA
    ECHO file name only: %%~nA
    ECHO extension only: %%~xA
    ECHO expanded path with short names: %%~sA
    ECHO attributes: %%~aA
    ECHO date and time: %%~tA
    ECHO size: %%~zA
    ECHO drive + path: %%~dpA
    ECHO name.ext: %%~nxA
    ECHO full path + short name: %%~fsA)


Single line:

IF a==a ECHO line 1A ELSE ECHO line 1B

Multiple lines:

IF a==a (
    ECHO line 1A
    ECHO line 2A
    ECHO line 1B
    ECHO line 2B


IF a==b

IF NOT a==b

REM case insensitive
IF /I a==b


REM equals
IF a EQU b

REM not equals
IF a NEQ b

REM less than
IF a LSS b

REM less than or equals
IF a LEQ b

REM greater than
IF a GTR b

REM greater than or equals
IF a GEQ b

Is variable defined?

IF DEFINED variableName

IF NOT DEFINED variableName

Does file exist?

IF EXIST filename

IF NOT EXIST filename

FOR Loop

Single line:
Loop through each file in current directory:

FOR /r %%A IN (*) DO ECHO %%A

Multiple lines:
Loop through each file in current directory:

FOR /r %%A IN (*) DO (
    ECHO line 1
    ECHO line 2