How to write your own bat file to create a backup copy. Writing bat files - examples of batch files

Instructions

Run program Notepad to create a Bat file. Next, enter the file text. It will be different depending on what you want to run with it. For example, create a bat file to connect to the Internet if your connection requires a login and password.

This can be done if Internet access itself is already configured and a shortcut for connecting to the Internet exists. In the file you need to enter the following text: Radial “Enter connection name” “Enter login” “Enter password”. For example, radial megafon-moskva sdk23SsdkP1 125523.

Save the resulting file. To do this, execute the command “File” – “Save As”, enter any file name, then enter the *.bat extension. Now you can add a shortcut to a file in startup so that the Internet connection is made automatically when the operating system starts.

Use the start command when creating a Bat file to launch applications. To do this, enter the following text in the file: start “Enter the full path to the program/file.” Please note that long folder and file names must be shortened using the ~ symbol, for example, instead of the name C:/Program Files, enter C:/Progra~, provided that there are no more folders on the disk that begin with these symbols.

Save the file in the same way as step 3. If you save the program to run in the folder with the program, there is no need to enter the full path to the application in it; it is enough to specify only the executable file, for example, start “Winword.exe”. You can place the shortcut for this file anywhere on your computer. You can also use batch files to create files, for example, to create a file named Program.txt on drive C, use the following command: @echo Start file>C:/Program.txt.

In order to watch a video posted online, it is not at all necessary to download it to your computer. You can view it online. To do this, it is enough to complete the series simple recommendations.

Instructions

First of all, you will need to install a flash player. This program will allow you to view clips in mode, regardless of the resource on which the file is located. To do this, follow the link http://get.adobe.com/ru/flashplayer/ and click on the Download button located in the center of the page. Save the file and run it. After launching the installation window, you will need to close your browser. Carry out this action, then complete the installation and launch the browser again. After this, you will be able to watch the video online.

To watch the video High Quality You will need to maximize your download speed. Most in an effective way To increase speed, you need to change the tariff plan according to which you access the network. Swipe comparative analysis offers from network access service providers in your city, then select one tariff plan, which is most suitable for you.

If the previous step does not suit you, minimize the number of programs using the network connection on your computer. With this step, you will free up the network access channel for downloading videos when watching online. Disable download managers, torrents, and all programs that are currently downloading updates. Close applications located on the taskbar, as well as those in the tray. Make sure they are disabled by launching the task manager and going to the processes tab. There you can also close applications that download updates - you can identify them by the word update in the name.

A BAT file is a program code saved with the extension .bat or .CMD as you like.

The possibilities of bat files are almost limitless, but as a rule, programmers use these extensions in simple and routine matters.

Using the bat file, you can open files on your computer, copy, move and delete files with or without a mask, run scripts third party programs, open the browser with the desired url. I often use such files to open ftp folders on a remote server.

How to create a bat file

Creating baht files couldn't be easier. Open a regular text editor and save it with the .bat extension.

You can also use the advanced program “notepad++”

Here is a sample code to write bat file:

explorer.exe "C:\Program Files"

This code will open the “program files” folder on the C:\ drive

Writing .bat files requires special care from the computer user. Since batch files can delete entire directories, format a computer partition

Here is a code example - formatting the F:\ partition

@echo off
format F /q /autotest

Example bat code - Create 100 folders:

@echo off
for /l %%i in (1,1,100) do mkdir "dir %%i"

You can make a bat and (Virus) a harmful program script: For example, the code below will delete important exe files.

@echo off
do del "c:\windows\exploer.exe"
do del "c:\windows\mspoint.exe"
do del "c:\windows\notepad.exe"

Command to create a folder with a bat file

The code below will create 3 folders in the location where the file itself is located. Also, the first folder created will contain another subfolder. Since the folder names are written in Cyrillic, we add the encoding line chcp 1251. Such a file cannot be written with a regular notepad, since it is not possible to change the encoding of Russian letters. Use notepad++.

chcp 1251
MD .\folder_article\base\
MD .\directory\
MD .\storage\

Download Bat file

- the file creates 3 folders

Example bat code how to open a folder

explorer.exe "C:\Users\Administrator\Desktop\photo\"

How to open bat format?

Just like creating .bat files in a text editor, they can be opened with the same notepad, wordpad, or notepad++.

The only thing to remember when opening a bat file is that when you double-click on the file, it will launch the program. That is, to open it for editing, move the cursor over the file being edited and right-click to open the context menu where select open with notepad++

Also, if you click on just open in the context menu, you will also launch the execution of the bat file.

There is another way: Open the text editor Notepad and drag your edited file into it.

Important: users often confuse the concepts of files with the extension .bat and mail client"The Bat" for sending and receiving mail documents.

Basic Bat File Operators

@ All commands executed by bat are displayed on the screen, to remove unnecessary things, a “dog” is placed in front of the command. Often used with @echo off.
set Sets variables. For example, setper=c:\windows here per assigns the path. You can write a cumbersome value to a variable and specify it in the script, which makes the code more compact. If its content changes, then you will not have to change the values ​​everywhere where this variable is provided.
:: One of two methods for commenting in a bat file without displaying this line on the screen.
:LABEL When you add a colon to a word, a label is created that allows you to jump to different sections of the body file. A label can have a different name, LABEL is an example.
CALL Bat command calling one batch file within another. All parameters described in one of the files can be passed to each other.
CHOICE Select command.
CLS Clears the shell contents that are displayed above the CLS.
ECHO Displays a message on the screen. For example, “ECHO How are you!” will display “How are you!” If you don't use @ECHO off at the beginning of the batch file, then you will see the path to the bat file and two messages, which is unnecessary. You can create an empty line by typing ECHO. with a period at the end.
EXIT Ends the current batch script.
GOTO LABEL Used to jump to a specific label, in this case LABEL, and execute the script after it.
IF As in the bat programming languages, the if command represents the fulfillment of a condition, depending on which the script will go along one path or another. Please refer to the help for the syntax.
for A loop used to organize the same actions over and over again.
PAUSE If you need to see the output of a script and it runs and the window closes quickly, then use PAUSE. It will allow you to view the result and complete the script by pressing any button.
R.E.M. Second way to comment. Unlike:: is printed on the screen if there is no @ECHO off construct.
SHIFT Changes the position of batch parameters in the bat file.
START Launches programs, windows, etc. Has many attributes.

For more detailed description bat file code, read Windows Help

In this article we will look at this useful thing How " batch file" Let's first define what a bat file is. Batch or batch files are simple text files containing sets of commands ( instructions) interpreter and having the extension bat or cmd ( cmd only work in NT family OSes). You can create and edit such files using a regular notepad or any other text editor.

Now you may ask, why do you need to be able to write such bat files? And why are they needed? I'll try to explain.

Firstly, they are used to make work easier, i.e. for example, you need to constantly perform some operation every day ( for example, create an archive of certain documents), with the help of a body file, this can be automated, and you will no longer take part in it.

Secondly, these batch files are very powerful ( if, of course, you know how to write them), i.e. You can even write a good program ( I mean in terms of functionality). Personally, they help me a lot in my work, and I simply forgot about some things when I did it manually.

Now let's move directly to the basics of these batch files. How are they created? You just need to create a simple text document, open it and immediately go to the “ tab File->save as", enter instead of the extension " Text document.txt", For example " Text document.bat" and save, so we get a batch file with the .bat extension, but it doesn’t do anything yet.

To begin with, I will give an example of a batch file that I use at my work to archive documents.

"C:\Program Files\WinRAR\winrar.exe" a -r -dh -ed -agYYYY-mm-dd E:\arhaccounts\ d:\accounts\*.doc "C:\Program Files\WinRAR\winrar. exe" a -r -dh -ed -agYYYY-mm-dd E:\arhaccounts\ d:\accounts\*.xls "C:\Program Files\WinRAR\winrar.exe" a -r -dh -ed -agYYYY -mm-dd E:\arhaccounts\ d:\accounts\*.txt

Now I’ll tell you a little about what this batch file does. WinRar starts, then Winrar commands follow:

  • a - this is to add to the archive;
  • -r - process subfolders;
  • -dh - open shared files;
  • -ed - do not add empty folders;
  • YYYY-mm-dd - add the current date to the archive name ( date format);
  • E:\arhaccounts\ - path where the final archive will be located;
  • d:\accounts\*.doc - path and mask of files that need to be archived.

In this case, we archive everything Word documents, Excel and text files; we do not need to archive the rest. Our archiving goes to another disk, and we also copy the resulting archive to another computer, so that the archives are stored in another office. Copying takes place over the network, so the computer to which the archive is copied must be turned on. To do this you can use the following command:

Copy E:\arhaccounts\*.rar \\namecomp\arhiv\

Examples of commands for bat files

Now let's consider basic commands, which you can use.

If you need to delete a file, write the following:

Del d:\file\test.doc


To delete the entire directory, write:

Rd d:\file\

If you need to delete everything from some directory every time, then use this:

Echo Y| del d:\file\

  • del d:\file\ - this is precisely the deletion of all files;
  • echo Y| - the command confirms the deletion because If you do not enter this command, you will see a message confirming the deletion - “Continue”, and you will need to answer this question every time.

Now let's look at a more complicated example, in which the condition is already met:

@echo off "C:\Program Files\WinRAR\winrar.exe" x -O+ -IBCK d:\test\test.rar d:\test IF not EXIST d:\test\123.rar GOTO 1 IF EXIST d: \test\123.rar GOTO 2:2 "C:\Program Files\WinRAR\winrar.exe" x -O+ -IBCK d:\test\123.rar c:\ del d:\test\123.rar:1 del d:\test\test.rar end

Now I’ll explain, let’s say you need to unzip the test.rar archive, which will contain many files, but if there is a 123.rar file there, it will need to be unzipped to the root of drive C, and the rest of the files will remain untouched in the same directory.

In order, the @echo off command is needed so that nothing is reflected on the screen ( basically, if you don’t need to, you can omit writing this line). Next, we launch Winrar and unpack the test.rar archive into the test folder. Then comes the condition if in the test folder ( after unpacking test.rar) we do not have the file 123.rar, then we simply execute the batch file and go to line: 1 and then simply delete the test.rar file as it is not necessary because We have already unpacked everything we need. But if there is a file 123.rar there, then the execution of the batch file goes to line: 2, after which the file 123.rar is already unpacked to the root of drive C. In other words, we have the condition met, if there is a file, then do this, if there is no file, do this. For example, if you do not specify the condition in in this example, then our batch file will give an error when we do not have the 123.rar file in this folder.

Now let’s look at an example: let’s say you need to move files from a directory located on drive D to a flash drive every time. Each time you will have to go to my computer drive D, select the desired folder, select all the files from it and cut it, and then just go to the flash drive and paste it. With the help of a body file this is done in one click ( with one condition that each time the flash drive will be, for example, drive G or whatever you have). Here is an example of such a batch file:

Move "D:\catalog\*.doc" G:\catalognaflehe\

And all files with the doc extension that are located in the D:\catalog directory will be moved to the flash drive. Now I want to say that you can use scripts in batch files ( scripts) using Windows Scripting Host and if necessary, for example, to display a message after files have been copied ( previous example) paste this:

Echo var WSHShell = WScript.CreateObject("WScript.Shell"); > %temp%\mes.js echo WSHShell.Popup("Files Copied"); >> %temp%\mes.js start %temp%\mes.js deltree /y %temp%\mes.js

In fact, you can talk a lot about writing batch files and, of course, this cannot be fit into one article; here I showed only the principles that are used when writing bat files, the basis, so to speak. If you want to know more commands for writing batch files, you can easily view them by typing ( Start - Run – cmd) the help command, but, of course, there are not all the commands that can be used in batch files. Good luck writing BAT files ( body shirts).

Continuation of the topic in the article -

In this article, we will look at two ways to create a bat file: using Explorer and using Notepad. This will be enough to create new bat files, but first let’s decide what they are for. To put it simply, the bat file is needed to write down a set of commands once Windows command line, and then execute them at any time without typing each time. All in all, perfect option for lazy and/or system administrators. =)

I'll get straight to the point:

Method one. We create bat file V " Conductor»

Let me make a reservation right away that this method requires that there be Enabled display of file extensions in Explorer. This is convenient in many cases and I don't understand why this feature is disabled by default in Windows.

Changing its extension(what is after the last dot) on .bat:

After we press Enter, Windows will ask “After changing the extension, this file may no longer be accessible. Make the change?" Well, of course “Yes”! This is exactly what we are trying to achieve: change the .txt extension to .bat:

Voila! We received a “batch file”, i.e. an executable file in which you can enter commands that will be executed when it starts:

Method two. We create bat file V " Notepad»

To create a bat file using " Notepad", need to open Notepad(or any text file in Notepad) and use the menu " File", option "":

A file saving window will open. It is important to take into account 2 things:

  1. « File type» must be displayed on All files (*.*)
  2. « File name" must have the extension .bat

We look where we save (to find it later) and press the button “ Save»:

Total:

Any of these methods makes sense if you have administrator rights. But the first one requires additional settings (which I still recommend changing and applying).

As you know, operating systems with graphical user interfaces did not always “run” computers. Even before their appearance, DOS-like operating systems were often used, in which special commands had to be entered to perform any actions. And it was from them that the principles of creating and executing so-called batch files were borrowed.

Despite loud statements from Microsoft that support for MS-DOS was discontinued a long time ago, if you think about it, it’s not difficult to realize that the same command line or PowerShell console works on exactly the same principles. And for them, sometimes it is completely unnecessary to enter certain commands that initiate the execution of certain actions. You can easily write your own code and save it in a special BAT file, after running which the actions will be performed automatically. But how to create a BAT file in Windows 7 or OS lower or higher? There are several for this simple ways, about which further and we'll talk. But first you need to find out what these objects are and what they can be used for.

What is a batch file?

In general, today there are two main types of such files, dividing them solely by extension: either BAT or CMD. Since such objects are very similar to each other both in content and in execution principle, so that there is no confusion, we will consider specifically issues related to how to create a BAT file in Windows 7 and higher (although the proposed solutions apply equally to earlier modifications).

A BAT file, or in common parlance a “bat file,” is a very ordinary text document containing a set of specific commands that are executed sequentially as you move from one line of code to another. However, sets can contain many additional statements, including looping the execution of some action (loop) or jumping under certain conditions (if, goto, etc.). If you look at the second two operators, it will become clear to many that they were used in such ancient and primitive programming languages, which include Basic. Despite this, they modern stage developments in computer technology are also successfully used in more “advanced” languages ​​(for example, when writing scripts in VB or Pascal).

What are they for?

As for the purpose of such files, for the most part they are used to automate some, so to speak, routine processes, most often associated with primitive actions such as copying or moving data, sequential launch of several programs, etc. For some reason, it is believed that This is the prerogative of system administrators, however, for many users, knowledge about the structure of such objects can also be useful (for example, to launch certain types of applications in the Windows environment via the command line, if the usual start of an EXE file for some reason operating system is blocked, or some system setting is unavailable for change).

Windows Batch File Examples

We’ll talk about how to create a BAT file in Windows 10 and lower a little later, but for now, to bring final clarity to the most effective use of such objects in Windows systems, let’s look at a few interesting examples.

So, probably, all those users who at one time worked with the first modifications of Windows know that they previously contained a special file Autoexec.bat, which was responsible for the configuration of the system when it started, and the user could add execution commands to it himself necessary applications like cleaning up disk space, creating copies of important data, etc. It was only much later that a special configurator appeared in the system, called by the msconfig command.

Another rather unusual example can be given for tablet PCs based on Windows RT versions 8 and 8.1, in which applications are installed exclusively through the Windows Store, and third-party software cannot be installed.

A solution was found and presented by a group of enthusiasts in the form of a small utility RT_Jailbreak 1.20, which contains a “batka” that allows you to disable verification of digital signatures of installed applications (without a Microsoft signature, installation is impossible, as well as disabling checks using the system itself, in which such tools are blocked) .

No less interesting is the batch file from the Windows RT Development Tool, which allows you to restart the system in developer mode.

And, of course, the SignTool program turned out to be a very necessary utility, presented precisely in the form of a batch BAT file, allowing you to execute for any software and its components in the form of executable EXE files and accompanying DLLs, so to speak, “re-signing” by changing the original digital signature to a Microsoft signature.

How to create a BAT file in Windows using Explorer?

But let's get back to creating package objects. How to create a BAT file using the system's built-in file manager? Elementary!

Using RMB on an empty space in a given location, select the “Create...” section, and then go to the creation point text document. After his appearance in work area the file just needs to be renamed, giving it an arbitrary name and the corresponding BAT extension separated by a dot. Please note that when performing such an operation, the display of extensions must be enabled.

How to create a file with the BAT extension in Notepad?

Since, as mentioned above, the “batnik” is a text file, there is another solution that involves using the standard text editor “Notepad”. How to create a BAT file in this case? Simple too!

Enter the necessary commands, and then use the file menu to save the file, but set the document type to “All files”, and in the name field enter the desired name with the BAT extension separated by a dot. User reviews indicate that this method is used most often.

Note: Just in case, it is worth noting that registry files are created in the same way, if necessary.

Using the FAR file manager

Finally, let's look at how to create a BAT file in one of the popular file managers called FAR Manager, which was created in the image and likeness of “Grandfather Norton” (Norton Commander).

To do this, use the key combination Shift + F4, after which the file name with the extension separated by a dot is entered in the file name field, the enter key is pressed, and an empty file is saved by pressing Shift + F2, which corresponds to the command “Save As...” . You can edit the contents by entering the necessary commands through the corresponding “Edit” function, called by pressing the F4 key. As for commands, it is better to study them yourself in advance. But for all those who want, for example, to create a folder using a BAT file, you can offer the MKDIR command or its abbreviated version MD FolderName, where FolderName is the name of the directory. By and large, the command can be complicated by specifying a location on the disk and selecting a user. And in general, for almost all commands you can use absolutely any variables, which in commands are enclosed in percent symbols on both sides.

Epilogue

That's all for the question of how to create a BAT file on Windows systems, using a few simple tools. Which of them is the simplest is up to the user to decide, but for the convenience of simultaneously creating a “batch file” and editing it, it is best to use either Notepad (or another similar text editor) or FAR Manager.