This is a draft cheat sheet. It is a work in progress and is not finished yet.
Enable delayed environment variable expansion.
FOR %variable IN (set) DO command [command-parameters]
Loop against a set of files
FOR /F ["options"] %%parameter IN (filenameset|"Text String") DO command
delims=xxx - The delimiter character(s) (default = a space)
skip=n - A number of lines to skip at the beginning of the file. (default = 0)
eol=; - Character at the start of each line to indicate a comment (default = semicolon)
tokens=n - Specifies which numbered items to read from each line (default = 1)
1) Use the alternate quoting style:
2) Use double quotes for long file names in "filenameset".
3) Use single quotes for 'Text string to process'
4) Use back quotes for
command to process
FOR %%a IN (%*) DO ECHO %%a
**Creates a pause for 2 seconds
CHOICE /T 2 /D Y > NUL
Batch Parameters Modifiers
%~1 - expands %1 removing any surrounding quotes (")
%~f1 - expands %1 to a fully qualified path name
%~d1 - expands %1 to a drive letter only
%~p1 - expands %1 to a path only
%~n1 - expands %1 to a file name only
%~x1 - expands %1 to a file extension only
%~s1 - expanded path contains short names only
%~a1 - expands %1 to file attributes
%~t1 - expands %1 to date/time of file
%~z1 - expands %1 to size of file
The modifiers can be combined to get compound results:
%~dp1 - expands %1 to a drive letter and path only
%~nx1 - expands %1 to a file name and extension only
Changing a file extension to create a log file name:
Status query a service on a machine
SC localhost QUERY WPCSvc
Stop a service on a machine
SC \\SERVERNAME STOP WPCSvc
Help Us Go Positive!
We offset our carbon usage with Ecologi. Click the link below to help us!