Create a .bat executable file in Windows

See how to create a batch file (.BAT file) in the Windows operating system with simple steps.

command, prompt, script, batch, file, line, commands

What are batch files?

Windows batch files are a stack of simple commands that run on the Command Prompt (Command Prompt). When you open a Command Prompt window there you can give Windows various commands like copy, cls, echo etc.

All of these commands can be grouped into a .bat file and run in groups with just one click on the bat file, instead of typing one by one into one of the Command Prompt windows.

The batch file (batch file) so it is essentially an unformatted text file, since the commands in the Command Prompt are text. The extension of this file as we mentioned before is a .bat, but you can also see it as .cmd.

When users run a batch file, the Windows application opens the cmd.exe application, which undertakes to execute successively the commands contained within it, in the order in which they appear in the file. This way you can automate daily tasks and shorten the time required to do something.

How to create a batch file in Windows

A batch file is no different from an unformatted text file. And for this we will use the simplest word processor we have in our hands. The notebook!.

command, prompt, script, batch, file, line, commands

1. Open Notepad (notepad.exe). Alternatively you can open WordPad.
2. Write in the first row and as the first command @ Echo off
3. At the bottom line, start writing the commands to the Command prompt one below the other.
4. Save your file with whatever you also want with a .bat extension

You can now double click on it and your file will run. To edit the batch file, right-click on the BAT file and select Edit.

Examples of files

Example 1: Network control
Suppose you have frequent network problems. You constantly open the command prompt, typing ipconfig and ping Google for network troubleshooting. After a while you will realize that it would be a bit more efficient if you wrote a simple BAT file, put it on your USB stick and use it in sorry you're having a problem.

This file would look something like this:
@echo off
ipconfig
ping google.com

Example 2: Tell Command Promt to write something
You want to make the Command prompt write your own phrase. Let's say the text "Welcome to iGuru!". Then your commands should be the following:
@echo off
title Αυτή είναι μία δοκιμή!
echo Καλώς ήλθατε στο iGuru!
pause

Example 3: Take a backup
Do you want to Backup to an external drive (D) specific folders on your computer (C)? You can of course use a third-party application or just make your own with two commands each and all. And then tell Windows Schedule to run it automatically every night (or whatever time you want).

Your file will look something like this,
@echo off
xcopy "c:\fakelos pros antigrafi 1" "d:\fakelos backup 1" /E /H /Y /I /D /C /K /R /X /S
xcopy "c:\fakelos pros antigrafi 2" "d:\fakelos backup 2" /E /H /Y /I /D /C /K /R /X /S
xcopy "c:\fakelos pros antigrafi 3" "d:\fakelos backup 3" /E /H /Y /I /D /C /K /R /X /S
pause

I have been using this example for years now for the daily backup of my files to an external drive.

Do not assume that this is the only thing a junkie can do. The variety and parameters of these commands are huge. For those unfamiliar, we inform you that the command line is capable of many.

Read: 20 Command Prompt commands worth knowing

Learn the basics of Batch Scripting

Batch files use the same language as the command line. All you have to do is tell the command line what you want it to do using a file, instead of typing it in the command line. This saves you time and effort. It also allows you to put some logic, such as simple loops, conditional actions, etc.

Clearly you can use all of the Command Prompt commands, but here are some basic ones:

  • @ Echo: This parameter will allow you to see your work script in the command line. Basically this parameter is useful for viewing your work code. If problems arise from the batch file, you will be able to view issues related to your script using the echo function. Adding one off at the end of the command will allow you to quickly close your script once completed.
  • title: Providing the same function as a title tag in HTML will provide a title for the batch script in the command prompt window.
  • class: Clears your command prompt window.
  • rem: Abbreviation of remark. Provides the same functionality as the label

    κάθε δημοσίευση, άμεσα στο inbox σας

    Προστεθείτε στους 2.087 εγγεγραμμένους.
command, prompt, script, batch, file, line, commands

Written by Dimitris

Dimitris hates on Mondays .....

Leave a reply

Your email address is not published. Required fields are mentioned with *

Your message will not be published if:
1. Contains insulting, defamatory, racist, offensive or inappropriate comments.
2. Causes harm to minors.
3. It interferes with the privacy and individual and social rights of other users.
4. Advertises products or services or websites.
5. Contains personal information (address, phone, etc.).