Create BATch file - CMD, BAT commands in Windows (DOS)


BATch commands date back to the DOS era and are still a useful tool for certain uses, yet Windows PowerShell is usually the better choice for administering and automating tasks today, see: Windows PowerShell.

The commands described here were tested under Windows 2000/XP, but are also valid for Windows 10 / 11.


The command "help" in the Command Prompt provides an overview of the available commands. With the command name and /? more detailed information about the respective command can be displayed, e.g. xcopy /?

Applications of batch files

Creating batch files:

Basic: echo / echo off, pause command:

 @echo off 
 echo This is a Textfile

small backup tasks with xcopy
Backup folder:

@echo off
 xcopy c:\Documents d:\save /D /E /Y /I

xcopy exclude

Set variables:

@echo off 
 set var=value
 echo %var% 

Windows variables:


@echo off 
 echo in the loop
 goto start 

TEST: does a file exist?:

if exist %file.txt goto jump
@echo off 
 if exist %datei.txt goto jump
 echo File not found
 goto END
 echo File does not exist


 @echo off
 xcopy c:\so c:\so2
 if errorlevel 1 goto error
 goto end
 echo copy was not successful!

Create a 2nd file, add:

echo hello > temp.txt 
echo hello >> temp.txt 


set year=%date:~-4%
set month=%date:~-7,2%
set day=%date:~-10,2%
echo %year%%month%%day%

creates then e.g.:20050921

Automate FTP:

 CD html 
 PUT C:\documents\homepage\index.htm 
 CD .. 
 CD images
 put C:\documents\homepage\images\image.gif image.gif 
ftp -s:dieftpdatei.ftp
curl -T C:\documents\homepage\index.htm --user USERNAME:PASSWORD

further topics or instructions for beginners

positive Bewertung({{pro_count}})
Rate Post:
{{percentage}} % positive
negative Bewertung({{con_count}})

THANK YOU for your review!

Publication: 2022-11-30 from Bernhard | Übersetzung Deutsch |🔔 | Comments:0

Programs Autostart - at login - Windows | Windows | Windows 10 / 11 - Download Installation - DVD or USB Boot

Top articles in this section

Windows : create a missing recovery partition

When cloning a large hard disk to a smaller one, I lost the recovery partition. So far not bad, Windows works without recovery partition, but in case of an error the partition helps to get the PC up and running again. To summarize, here's how it works with the recovery partition: As long as the partition is still there, it can be deactivated and written to a file. If the partition gets lost unexpectedly, it can be recovered from the Windows setup media. This post is also available as a video, se...

Windows 11 23H2 (Build: 22631.3447) : show current version

Build means the kernel version of Windows. How current the Windows 10 or Windows 11 installation is, can be seen by the build number used.

the 4 best tools to compare two text files

Anyone who frequently creates scripts or analyzes log files and handles different versions can compare them very quickly with the help of the right editor. 

Questions / Comments

By continuing to browse the site, you agree to our use of cookies. More Details