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.

Help

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
 pause 

small backup tasks with xcopy
Backup folder:

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

xcopy exclude

Set variables:

@echo off 
 set var=value
 echo %var% 
 pause 

Windows variables:

Jump:

@echo off 
 :start 
 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
 
 :jump
 echo File does not exist
 
 :END

Errorlevel:

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

Create a 2nd file, add:

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

Date

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:

OPEN www.ftpserver.com 
 username
 password
 
 CD html 
 ASCII 
 PUT C:\documents\homepage\index.htm 
 CD .. 
 
 CD images
 BINARY 
 put C:\documents\homepage\images\image.gif image.gif 
 bye 
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...


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. 


install driver via command line cmd: inf

Windows drivers can of course also be managed via the command line. Microsoft offers two different tools for this purpose: The PnPUtil integrated in Windows and as part of the Windows Driver Kit (WDK) the command: devcon.

Questions / Comments


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