Professional Documents
Culture Documents
help commandName xcopy /YS src as above without ask to missing loop over elements: indexed
commandName /? dest overwrite
xcopy /YS src copy to network share Functions: label and goto
help --> show all system commands
\\server\share echo "Hi:"
All System Commands robocopy /S src copies dirs and subdirs goto :good
dest except empty ones :bad
help
robocopy /YS as above without ask to echo "I don't like scripting"
Clear Screen src dest overwrite goto :eof
:good
Clear Screen cls
Parameters echo "I like scripting"
%0 Name of Script goto :eof
Shortcuts
? one arbitary character setlocal Only active in the move moves and renames file1 to file2
(file?.txt) set current batch file (local) file1 (path: dir/file2) file2 is overwritten
* ( *.bat) arbitary characters (0,1 or MY_ENV=abc dir/file2 from file1
more) endlocal move moves and overwrites file1 to file2
set creates or changes an /Y file1 without asking
File Show MY_ENV=abc environment variable file2
that is active in the cmd.
type file show file content
(global) File Names
more show file content pagewise
set shows the active enviro‐ Case-Insensitive
sort file show file content sorted
nment variables
Max. 260 characters incl. invisible termin‐
echo print variable out ating null character
Directory show Content
%USERNAME%
spaces and character set 128 - 255 allowed
current dir
defined returns
folder Never <, >, :, ", /, \, |, ?, *
MY_VAR 0 => Execution was
absolute dir C:\Windows Hint: A-Z, a-z, 0-9, _, spaces, ( underscore
successful
path as space )
>0 => Execution failed
dir Y: different drive *.bat & *.cmd
dir /B only show file names and IF Control Structures dir /B --> only show file names and directory
directory names Names
IF test (command) ELSE Syntax
(command)
Batch Files User Input Directory Rename & Move
@ echo off Syntax: set /P Control structures For rename renames dir1 in dir2
set /P name="Input var=prompt: dir1
for {%%|%}<Variable> in (<Set>) do <Co‐
yor name: " dir2
mmand> [<CommandLineOptions>]
echo Hi %name% variable call move if dir2 exist: dir1 into dir2 (path:
cmd.exe use ->%
dir1 dir2/dir1), else rename dir1 to
batch script use ->%%
Batch Files File Input dir2 dir2