Batch or batch files are plain text files containing sets of interpreter commands and having a bat or cmd extension (cmd work only on NT family operating systems). You can edit such files using notepad or any other text editor.

Open notepad and type the following two lines:

@echo This batch file
@pause

This batch file
Press any key to continue...

After pressing any key, the window will close, because bat file is done.
Please note that the dog symbol before each command in the bat file indicates that the command itself does not need to be displayed on the screen, but only the result of its work needs to be displayed. To experiment, remove the dog character from the beginning of each line, save and run the resulting bat file.

Commands used in bat files

The list of commands that can be used in bat files can be viewed by typing in the command line (Start - Run - cmd for Windows NT family or Start - Run - command for 9x line) command

The result of help is a list of available commands with brief explanations for them. To get more detailed information for the command of interest, type help command_name in the command line. For example, to get detailed help on the AT command keys, run the following command:

As a result, a list of keys for running the AT command from a bat file will be displayed on the screen.
If the bat file is executed under Windows control(not in pure DOS), then you can run any applications or open files from it. For example, you need to automatically open the log file of the bat file after its work is completed. To do this, just include the following command in the bat file on the last line:

start filename.txt

The result of executing this command will be the opening of the file filename.txt, and the bat file itself will complete its work. This method is good if the log file is small, otherwise Notepad will refuse to open it, offering to use WordPad. But this problem is also solvable, which will be shown in further examples.

How to automate the launch of bat files

Very often it is necessary to automate the launch of bat files to perform their routine operations. To run bat files on a schedule, the Scheduler, which is included in the standard delivery of Windows, is most suitable. With this help, you can very flexibly configure the launch of a batch file on certain days or hours, at a certain interval. You can create multiple schedules, etc.

To run batch files locally, you can use third-party solutions, the benefit of paid and free alternatives the standard Scheduler a great many.

Batch files can also be used as login scripts in domains. With their use in this way, they will be executed every time the user enters the network, regardless of his desire. With their help, you can automate the collection of information about machines or software installed on users' computers, forcibly change windows settings, install invisibly to the user software and automate other tasks that would take a very long time to perform manually.

How to create a file with an arbitrary name from a bat file

A redirect character is used to create a file during batch file execution. It looks like this:
>
Those. to create a file, you need to redirect the stream from the screen to a file. You can do this with the following command:

@echo Start file>C:\1.txt

After executing this command in the root of drive C will be created text file with the line Start file.
When creating a file, you can use system variables or parts of them in its name. For example, you can create a report file about the operation of a bat file with a name equal to the date the bat file was launched. To do this, you can use the following lines in bat file.

set datetemp=%date:~-10%
@echo .>%SYSTEMDRIVE%\%DATETEMP%.txt

These two lines work like this. First, we create a datetemp variable in memory, to which we assign 10 characters from right to left of the DATE system variable. Thus, now the temporary variable datetemp contains only the current date. In the next line, we redirect the output of the dot character to a file, whose name we take from the datetemp variable, and the txt extension is specified explicitly. The file will be created on system drive the computer where the bat file is running.

When an administrator collects information about computers on a network, it may be more convenient to append the computer name to the file name. This can be easily done with the following command:

@echo .>C:\FolderName\%COMPUTERNAME%.txt

This command, during the execution of the batch file, will create a text file on drive C with the name of the computer on which the batch file is being executed.
To create a file with a specific name, you can use any system variables, or create your own based on system variables and/or other data.

How to create folder from bat file

To create a folder, use the MKDIR command or its abbreviated counterpart MD. To create a folder from a bat file, you need to use the following command:

After executing such a command, the FolderName folder will be created in the folder from which the bat file is launched. To create a file in a location other than the bat file launch, for example, in the root of drive D, use an explicit indication of the location of the new folder. The command will look like this:

MD D:\FolderName

When creating folders, you can use system variables. For example, you can create a folder in the root of drive D with the name of the current user. To do this, you need the %USERNAME% variable, and the command will look like this:

MD D:\%USERNAME%

You can further complicate the command and create a folder with the name of the current user on the system drive of his computer. The command for this would look like this:

MD %SYSTEMDRIVE%\%USERNAME%

When creating folders or files, you can use any system variables or parts of them. The following example demonstrates how to create a folder on the system drive of the user's computer with a name equal to the current date.

set datetemp=%date:~-10%
MD %SYSTEMDRIVE%\%datetemp%

This construction works as follows.
The first command creates a datetemp variable in memory, which will be destroyed when the bat file ends. Until the bat file has finished its work, it is possible to operate with the value of this variable. The datetemp variable is assigned 10 characters from right to left of the DATE system variable, i.e. from current date. The DATE variable has the format Dn DD.MM.YYYY. The first characters from the left are the name of the day of the week, so we discard them and assign only the current date to the temporary variable datetemp.
This is not limited to the list of possibilities when creating folders. You can manipulate variables however you like, creating folders with unique, easy-to-read names. You can get a list of all variables with the SET command.

How to redirect the output of commands to a file

Often, when executing a complex bat file in automatic mode it is difficult to check the results of his work for many reasons. Therefore, it is easier to write the results of the batch file commands to a text file (log file). and then analyze the correct operation of the bat file according to this log.
Redirecting the result of the bat file commands to a log file is quite simple. The following will show how this can be done.
Create a .bat file with the following content (copy these lines into Notepad and save the file with the .bat extension):

@echo off
echo Start %time%
echo Create test.txt
echo test>C:\test.txt
echo Copy Test.txt to Old_test.txt
copy C:\test.txt C:\Old_test.txt
echo Stop %time%

The first line disables the output of the commands themselves. Thus, only the results of their execution will be written to the log file.
The second line writes to the log file the start time of the batch file.
The third line writes to the log file an explanation that the following command will create the file test.txt
The command from the fourth line creates the file test.txt from the root of drive C. The file is created for example. This command writes the word test to the file C:\test.txt
The fifth line outputs to the log file an explanation that the following command is copying a file from one location to another.
The command on the sixth line copies the created file C:\test.txt to the file C:\Old_test.txt, i.e. a copy of the file is created under a new name.
The last, seventh line contains the command to display the time when the batch file ended. Combined with logging the start time of the batch file to the log file, these two time values ​​provide an estimate of the run time of the batch file.

Save this batch file with a name such as 1.bat
Let's assume that we would like to store a report on the operation of a batch file in a separate folder and write a report every day with a new file name so that we can access the logs for previous days on any day. Moreover, I would like to have the name of the log file in the form of the date of operation of the batch file. To implement all this, let's create a folder on drive C (for example) with the name LOG, i.e. the full path to it will look like C:\LOG. We will run the created batch file 1.bat with the following command:

1.bat>C:\LOG\%date~-10%.txt

If the batch file will be launched from the Scheduler, then you need to specify the full path to the bat file. Remember that if there are spaces in the path, then you must use either quotes or the 8.3 format. That is, if the path to the bat file is C:\Program Files\1.bat, for example, then one of the following lines must be specified in the Scheduler command line to run the bat file:

"C:\Program Files\1.bat">C:\LOG\%date~-10%.txt
C:\Progra~1\1.bat>C:\LOG\%date~-10%.txt

After running the 1.bat file in the C: \ LOG folder, a file will be created with a name equal to the date the bat file was launched, for example, 01/13/2004.txt This will be a report on the operation of the batch file 1.bat
Running the bat file, an example of which is shown in the first listing at the top of the page with the above command, will create a log file with the following content:

Start 19:03:27.20
Create test.txt
Copy Test.txt to Old_test.txt
Files copied: 1.
Stop 19:03:27.21

Thus, to redirect the results of the bat-file to the log-file, you need to use the redirection symbol> The syntax is as follows:

Path\FileName.bat>Path\LogFileName.txt

The log file extension can be anything. If desired, a report on the execution of a batch job can be issued even in the form html pages(corresponding tags can be output to a log file as comments were displayed in example 1.bat) and copy it to the corporate server.

How to automatically respond to a confirmation request

Some commands require confirmation of a potentially dangerous action when executed. For example, commands such as format or del will first ask for confirmation for further execution. If one of these commands is executed in a batch file, then the confirmation prompt will stop the batch file from executing and wait for the user to select one of the options. Moreover, if the result of batch file execution is redirected to a log file, then the user will not see a confirmation prompt and the batch file will look frozen.

To fix such annoyances, you can redirect the desired response to the command. Those. execute reverse action to redirect the output of the command to a file.
Let's look at an example of how a request to confirm a potentially dangerous action looks like. Let's create on drive C, for example, a Folder folder. Let's create in it or copy any two files into it. Next, let's open command line and run the following command:

This command should remove all files from the specified folder. But beforehand, a request will be issued to confirm the following content:

C:\Folder\*, Continue ?

The execution of the command will stop until either the Y key or the N key is pressed. When a batch file is executed in automatic mode, its execution will stop.
To avoid this, we use a redirect. Redirection is carried out using the symbol
The vertical bar indicates that instead of displaying the character on the screen, it must be “given away” to the command following the character. Let's test the redirection. Run the following command on the command line:

echo Y|del C:\Folder

The screen will show a confirmation request to delete all files in the Folder, but with a positive response (Y). All files in the Folder will be deleted.
Be careful with this command.

How to disable the output of commands on the screen when executing a batch file

When a batch file is executed, the commands themselves are displayed on the screen, in addition to the results of the command. You can use the @ symbol to disable command output.
In order not to display a single command, you can put the @ sign at the beginning of this command.

This command will display the command echo Testing, and on the next line - the result of its work, the word Testing.

This command will display only the result of the command, i.e. the word testing. The command itself will not be displayed.
If you do not need to display commands on the screen during the execution of the entire file, then it is easier to write the following command in the first line in the batch file:

This command will disable the output of commands to the screen for the duration of the entire batch file. To prevent the command itself from being displayed, it begins with the @ symbol.

How to run another from one bat file

Sometimes, when executing a batch file, it becomes necessary to run another batch file. Moreover, in some cases, the execution of the main batch file must be suspended while the auxiliary file is being executed, and in others, the auxiliary file must run in parallel with the main one.
For example, let's create two bat files. One named 1.bat and containing only one command

The second one is named 2.bat and also contains one command

Now let's run the file 1.bat. A window will open in which you will be prompted to press any key to continue, after pressing which the window will close. Thus, calling from one batch file to another using the call command stops the execution of the batch file until the execution of the batch file called by the call command completes.

Otherwise, you need to run either an application or another batch file from a bat file without interrupting the execution of the main batch file. This often needs to be done, for example, by forcibly opening the operation log of a batch file scheduled for the night, so that in the morning the user can check the correctness of its execution. To do this, use the start command Let's fix the line in file 1.bat with

and run the file 1.bat Now a window has opened in which you need to press any button to continue, and the window of the main batch file (1.bat) has closed.
Thus, to call from one batch file to another, without stopping the work of the first batch file, you need to use the start command.
The above start and call commands can be used not only to launch other batch files, but also to launch any application or open files.
For example, start log.txt in the body of a batch file will open log.txt in Notepad without stopping the batch file.

How to send message from bat file

When a batch file is being executed on one of the machines on the network, it is convenient to inform the administrator of the completion of its execution by sending a message to the administrator's machine. You can do this by including the command in the batch file

net send name Message text

Where name is the name of the machine or user to which the message is addressed, and Message text is the text of the message. After executing this command, a message will be sent to the user name.
Please note that when using Cyrillic in the text of the message, the text must be typed in MS-DOS encoding (866 code page). Otherwise, the message will come in the form of unreadable characters. You can type text in DOS encoding using any text editor that supports this encoding. It can be, for example, FAR. Open the batch file in FAR for editing (F4) and press the F8 button. The top line of the editor should be DOS encoding, and at the bottom, at the hint about keyboard shortcuts, the F8 key should have the inscription Win, indicating that the current encoding is DOS and to switch to the Win encoding, press F8.

How to automate file deletion by type

To clear the disk of temporary files, you can use the command

del /f /s /q C:\*.tmp

Where
/f - deletes all files, even if they have the read-only attribute set
/s - removes files from all subdirectories
/q - disables the prompt for confirmation of file deletion
C: is the drive where the files will be found and deleted. You can specify not the entire drive, but a folder, for example, C:\WinNT
*.tmp - type of files to be deleted

Be careful with the /q switch and the types of files you delete. The command deletes without asking for permission, and if the wrong file type is specified, it can delete unnecessary ones.

How to change the IP address of a computer from a batch file

The IP address can be changed using the netsh command.
To correctly change the IP address, you first need to find out the current configuration. You can do this on the command line with the command

netsh interface ip show address

The result of this command is to display the current configuration of the network interface. We are interested in the name of the interface. Let's assume it's called FASTNET.
Suppose that you need to change the IP address to 192.168.1.42, the addressing in the network is static, without using DHCP, gateway 192.168.1.1, mask 255.255.255.0 In this case, the command to be executed from the batch file will look like this:

netsh interface ip set address name="FASTNET" static 192.168.1.42 255.255.255.0 192.169.1.1 1

After executing this command, the FASTNET interface will change its IP address to 192.168.1.42.
The netsh command provides extensive control over network settings from the command line. To get to know others functionality get help with netsh /?

How to get computer name from bat file

To find out the computer name when executing a bat file (to use this value later), use the command

This command returns the name of the computer it is running on.

How to rename files by mask from a batch file

Sometimes it becomes necessary to rename all files in a folder according to a template from a batch file. You can do this with the following command in a bat file:

for /f "tokens=*" %%a in ("dir /b PATH\*.*") do ren PATH\%%a Prefix%%a

In this line, you need to replace PATH\ with the path to the files that will be renamed, and Prefix with those characters that will be added to the file name when renaming.
Don't put the batch file in the folder where the rename happens, otherwise it will be renamed too. If the folder where the files are being renamed has subfolders, then a prefix will also be added to the name of the subfolder, i.e. subfolders will be renamed like files.
If you specify a specific mask for file types that are subject to renaming, for example, *.txt, and not *.* as in the example, then only files of the specified types will be renamed. Other files and folders will not be renamed.

Second option:
set thePATH=C:\test
for %%I in (*.txt) do ren "%thePATH%\%%~nxI" "%%~nI.dat"
How to use the percentage symbol in a batch file

To use the percentage symbol (%) in a batch file, you must write it twice. For example
echo 50%%
This command in the bat file will display 50%. If you use the echo 50% command, then only the number 50 will be displayed on the screen.
Keep this in mind when using the % symbol in batch files.

How to export the registry from a batch file

regedit.exe -ea C:\environment.reg "HKEY_CURRENT_USER\Environment"

This command, when executed in a batch file, will unload the HKEY_CURRENT_USER\Environment branch into the C:\environment.reg file. When you need to restore the settings in HKEY_CURRENT_USER\Environment, it will be enough to run the environment.reg file. This command can be used to make a daily backup of software and system settings that are stored in the registry.
Do not forget that if there is a space in the path where the output file should be saved or in the name of the registry branch, then they must be enclosed in quotes.

How to Import Registry Variables from a Batch File

If there is a need to import previously saved or new variable values ​​from a batch file into the registry, this can be done using the command

regedit.exe -s C:\environment.reg

This command imports data from the environment.reg file into the registry without prompting for confirmation by using the -s switch.

How to bypass date check from bat file

Some software checks the current system date on startup. If the date is greater than the one set by the developer, then the program does not start. For example, the developer believes that the version of the program can work for a month, and then the user will have to install updated version programs. On the one hand, this is a concern for the user, who will have at his disposal a fresh version of the program with the bugs fixed, in relation to previous versions. On the other hand, the manufacturer forces the user to download new version even if the user is completely satisfied with the version of the program that he has installed. This problem can be easily solved with the following batch file, which will run the program, wait for it to complete, and return the date to the date before the program was run.

set tempdate=%date:~-10%
date 01-01-04
notepad.exe
date %tempdate%

AT this example the current system date is first stored in a variable, then (on the second line) the system date is set to January 1, 2004, and then a program is called that checks the system date. In this example, it's Notepad. As long as Notepad is open, the batch file is pending, not ending, and not resetting the system date back. Once Notepad is closed, the batch file will continue executing and set the system date to the value stored in the tempdate variable, i.e. to the one that was before running the batch file.

Do not forget that if the path to the file with which the program is launched contains spaces, then it (the path) must be enclosed in quotes. If the path contains Cyrillic, then when writing a batch file, you must use a text editor that supports DOS encoding (for example, FAR). Otherwise, when you run the batch file, you will get a message stating "The specified file is not an internal or external command...".

If the program checks the current system date only when it is started and does not do this again during operation, then the batch file can be modified by adding the start statement before the name of the program executable file, i.e. our example will look like this:

set tempdate=%date:~-10%
date 01-01-04
start notepad.exe
date %tempdate%

In this case, the batch file will change the system date, launch the program and, without waiting for its completion, return the date to the one that was before the program was launched.

How to wait for a specific file in a bat file

Sometimes it is necessary to perform some action when a certain file appears in a folder. To check the existence of a file in a folder, you can use the following batch file

:test
if exist c:\1.txt goto go
sleep 10
goto test
:go
notepad

Such a batch file will check with an interval of 10 seconds for the presence of the 1.txt file in the root of the C drive, and when the 1.txt file appears, the action indicated after the go label will be performed, i.e. in this example, Notepad will be launched.
The sleep utility is freely distributed as part of the Resource Kit. You can download it here.
If the 1.txt file is large and copied from somewhere, it may happen that the batch file checks for its existence while the file has not yet been copied or is being occupied by another application. In this case, an attempt to perform some actions with the 1.txt file will result in an error. To prevent this from happening, the batch file can be modified as follows

:test
if exist c:\1.txt goto go
sleep 10
goto test
:go
rename c:\1.txt 1.txt
if not errorlevel 0 goto go
del c:\1.txt

When the 1.txt file is not completely copied to drive C, or is occupied by another application, an attempt to rename it will cause an error and the cycle will repeat until the file is completely copied or freed. After the rename c:\1.txt 1.txt command is executed without error (that is, the file is free), then you can perform any actions with it. In the last example, this is its removal.

How to add comments to bat file

When writing a large batch file, it is very useful to add comments to its main blocks. This will make it easy to figure out what these blocks do over time.

Windows Bat files are a convenient way to perform various tasks on a PC, which is actively used by computer craftsmen. They allow you to automate everyday tasks, reduce their execution time and turn a complex process into something feasible for an ordinary user. This article presents basic features batch files and tips for writing them yourself.

Automation made easy

How to create a bat file? To do this, follow these steps:

  1. In any text editor, such as Notepad or WordPad, create a text document.
  2. Write your commands in it, starting with @echo , and then (each time on a new line) - title [name of the batch script], echo [message to be displayed] and pause.
  3. Save the text in an electronic document with the .bat extension (for example, test.bat).
  4. To launch, double-click on the newly created batch file.
  5. To edit it, click on it. right click mouse and select "Edit" from the context menu.

The raw file will look something like this:

title This is your first bat file script!

echo Welcome to the script batch processing!

More details about the bat-file commands and their use will be discussed below.

Step 1: Create a Software Script

Let's assume that the user often has problems with the Network. He constantly uses the command line, typing ipconfig and pinging Google to troubleshoot the network. After a while, the user realizes that it would be much more efficient if he wrote a simple bat file, put it on his USB drive, and run it on the computers he diagnoses.

Create a new text document

A batch file makes it easy to perform repetitive tasks on your computer using a command line. Windows strings. Below is an example of a script responsible for displaying some text on the screen. Before creating a .bat file, you should right-click on an empty space in the directory and select "Create" and then "Text Document".

Adding code

Double clicking on this new text document will open the default text editor. You can copy and paste the code example above into a text entry.

Preservation

The above script prints the text "Welcome to the Batch Script!" on the screen. Electronic document must be recorded by selecting the menu item of the text editor "File", "Save as", and then specify the desired name of the bat-file. It should end with a .bat extension (for example, welcome.bat) and click OK. For the correct display of the Cyrillic alphabet, in some cases it is necessary to make sure that right choice encodings. For example, when using the console Russified Windows systems The NT document must be saved to the CP866. Now you should double click on the shortcut of the bat file to activate it.

But the screen will display:

"Welcome to the batch script! Press any key to continue..."

If the bat file does not start, users recommend going into the registry and deleting the key:

"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.BAT\UserChoice".

Do not think that this is all that batch scripts are capable of. Script parameters are modified versions of command line commands, so the user is limited only by their capabilities. And they are quite extensive.

Step 2: Getting to Know Some Commands

If a PC user is familiar with how to execute DOS console commands, then he will be a wizard for creating program scripts, because it is the same language. The lines in the bat files will tell the cmd.exe interpreter everything that is required of it. This saves time and effort. In addition, it is possible to define some logic (for example, simple loops, conditional statements, etc., which are conceptually similar to procedural programming).

Built-in commands

1. @echo is a bat file command that will allow you to see the script running on the command line. It is used to view the progress of the working code. If the batch file has any problems, then this command will allow you to quickly isolate the problems. Adding off makes it possible to quickly complete code execution, avoiding displaying unnecessary information on the screen.

2. Title provides the same functionality as the tag in HTML, i.e. creates a title for the batch script in the command line window.</p><p>3. Call calls one bat file from another or a subroutine within one script. For example, the power function calculates the power %2 of the number %1:</p><p>if %counter% gtr 1 (</p><p>set /a counter-=1</p><p>endlocal & set result=%prod%</p><p><img src='https://i2.wp.com/syl.ru/misc/i/ai/324915/1862019.jpg' width="100%" loading=lazy loading=lazy></p><p>4. Cls clears the command line. Used to make the previous output <a href="https://bar812.ru/en/izmenenie-ekrana-blokirovki-na-android-blokirovka-ekrana-na-android-kak.html">foreign code</a> prevented viewing the progress of the current script.</p><p>5. Color sets the font and background color. For example, <a href="https://bar812.ru/en/komanda-zamenit-cvet-replace-color-v-fotoshope-opisanie-instrumenta.html">color command</a> f9 sets white letters on a blue background. A command without a parameter restores the default settings.</p><p>6. Echo is used to output information, as well as enable (echo on) or disable (echo off) such an output. For example, the echo command. displays <a href="https://bar812.ru/en/nevernoe-kolichestvo-kategorii-v-ishodnoi-stroke-1s-novye-funkcii-raboty-so.html">new line</a> without a dot, but echo . - point. Without parameters, the command displays information about its current status - echo on or echo off.</p><p>7. Rem provides the same functionality as a tag<! в HTML. Такая строка не является частью выполняемого кода. Вместо этого она служит для пояснения и предоставления информации о нем.</p><p>8. Pause allows you to interrupt the execution of bat-file commands. This makes it possible to read the executed lines before continuing the program. The message “Press any key to continue...” is displayed on the screen.</p><p>9. Set allows you to view or set environment variables. With the /p switch, the command prompts the user for input and saves it. With the /a option, it allows you to perform simple <a href="https://bar812.ru/en/arifmeticheskie-operacii-v-vba-slozhenie-vychitanie-umnozhenie-delenie-i.html">arithmetic operations</a>, also assigning their result to a variable. When operating on strings, there must be no spaces before or after the equals sign. For example, the set command displays a list of environment variables, set HOME displays the values ​​of arguments beginning with “HOME”, and set /p input=input integer: prompts for an integer and assigns it to the appropriate variable.</p><p>10. Start "" [website] will launch the specified website in the default web browser.</p><p>11. If serves to test <a href="https://bar812.ru/en/sushchestvuyut-opredelennye-trebovaniya-k-usloviyam-okruzhayushchei-sredy-v-kotoryh-dolzhen.html">certain condition</a>. If it is true, then the command following it is executed. There are 3 types of conditions:</p><ul><li>ERRORLEVEL number - checks the exit code of the last executed instruction to match or exceed the specified number. In this case, 0 indicates the successful completion of the task, and any other number, usually positive, reports an error. For example, you can use nested commands to determine the exact exit code: if errorlevel 3 if not errorlevel 4 echo error #3 occurred.</li><li>Line1 == line2 - check if two strings match. For example, if "%1"= ="" goto ERROR does not have an external parameter, it will pass control to the label ERROR.</li><li>EXIST name - check for the existence of a file with the specified name. For example if <a href="https://bar812.ru/en/reshaem-problemu-game-resource-path-does-not-exist-kak-vosstanovit-wot-klient-bez-polnoi.html">not exist</a> A:\program.exe COPY C:\PROJECTS\program.exe A: Copies the program program.exe to drive A if it is not there.</li> </ul><p>12. Else must be on the same line as the If command. Indicates the need to <a href="https://bar812.ru/en/skachat-framework-poslednyuyu-versiyu-x64-chto-takoe-net-framework-dlya-windows-xp-i-kak-ego.html">next instruction</a> if the expression evaluates to false.</p><p><img src='https://i1.wp.com/syl.ru/misc/i/ai/324915/1862021.jpg' width="100%" loading=lazy loading=lazy></p><p>13. For is used to repeat certain actions with each member of the list. It has the format for %%argument in (list) do command. The argument can be any letter from A to Z. The list is a sequence of strings separated by spaces or commas. Wildcards can also be used. For example:</p><ul><li>for %%d in (A, C, D) do DIR %%d - sequentially displays the directories of disks A, C and D;</li><li>for %%f in (*.TXT *.BAT *.DOC) do TYPE %%f - prints the contents of all .txt-, .bat- and .doc-files in the current directory;</li><li>for %%P in (%PATH%) do if exist %%P\*.BAT COPY %%P\*.BAT C:\BAT - copies all batch files that exist in all directories of the search path to C:\ WAT.</li> </ul><p>14. A colon (:) in front of a word forms a link from it, which allows you to skip part <a href="https://bar812.ru/en/bezobidnyi-confirm-php-kak-dobavit-okno-podtverzhdeniya-v-php-pered-udaleniem.html">program code</a> or go back. Used with the Call and Goto commands, indicating from which point the execution of the bat file should continue, for example, if a certain condition is met:</p><p>15. Variables:</p><ul><li>%%a stands for each file in the folder;</li><li>%CD% - current directory;</li><li>%DATE% - system date, the format of which depends on localization;</li><li>%TIME% - system time as HH:MM:SS.mm.;</li><li>%RANDOM% - generated pseudo-random number in the range from 0 to 32767;</li><li>%ERRORLEVEL% - exit code returned by the last executed command or bat script.</li> </ul><p>To extract the part of the string that is contained in the variable, given its position and length, you can do this:</p><p>%[variable]:~[start],[length]%. For example, to display a date in the format DD/MM/YYYY as YYYY-MM-DD, you can do this: echo %DATE:~6.4%-%DATE:~3.2%-%DATE:~0.2%.</p><p>16. (". \") - <a href="https://bar812.ru/en/html-absolyutnye-i-otnositelnye-ssylki-sozdanie-ssylki-otnositelno.html">The root folder</a>. When working with the console, before changing the file name, deleting it, etc., you must direct the action of the command to a specific directory. When using a batch file, just run it in any desired directory.</p><p>17. %digit - accepts the values ​​of the parameters passed by the user to the bat-file. May be separated by spaces, commas, or colons. "Digit" is a number between 0 and 9. For example, %0 takes the value of the current command. %1 matches the first parameter, and so on.</p><p>18. Shift - command used to shift <a href="https://bar812.ru/en/dlya-chego-ispolzuyutsya-hranimye-procedury-hranimye-procedury-primer-sozdaniya.html">input parameters</a> for one position. Used when external arguments are passed to a batch file. For example, the following .bat file copies the files specified as options on the command line to drive D:</p><p>if not (%1)==() goto next</p><p>In addition, the following manipulations can be performed with arguments:</p><ul><li>%~ - remove surrounding quotes;</li><li>%~f - expand the parameter to the full path name along with the drive name;</li><li>%~d - show disk name;</li><li>%~p - display path only;</li><li>%~n - select only the file name from the parameter;</li><li>%~x - leave only the extension;</li><li>%~s - convert path to representation with short names;</li><li>%~a - extract file attributes;</li><li>%~t - display creation date and time;</li><li>%~z - display file size;</li><li>%~$PATH: - searches the directories listed in <a href="https://bar812.ru/en/php-vse-peremennye-kak-vyvesti-znacheniya-vseh-peremennyh.html">environment variable</a> PATH, and expands the parameter to the first matching fully qualified name found, or returns an empty string on failure.</li> </ul><p><img src='https://i0.wp.com/syl.ru/misc/i/ai/324915/1862020.jpg' width="100%" loading=lazy loading=lazy></p><h2>Wildcards</h2><p>Many commands accept filename patterns, characters that match a group of filenames. Wildcards include:</p><ul><li>* (asterisk) - denotes any sequence of characters;</li><li>? (question mark) - replaces one (or 0) character other than a dot (.).</li> </ul><p>For example, the command dir *.txt lists txt files, and dir ???.txt lists <a href="https://bar812.ru/en/sozdanie-kompleksnyh-dokumentov-v-tekstovom-redaktore-ms-word.html">text documents</a>, whose name length does not exceed 3 letters.</p><h2>Functions</h2><p>Like subroutines, they are emulated using call, setlocal, endlocal, and labels. The following example demonstrates the ability to define a variable that stores the result in a call string:</p><p>call:say result=world</p><p><img src='https://i0.wp.com/syl.ru/misc/i/ai/324915/1862022.jpg' width="100%" loading=lazy loading=lazy></p><h2>Computing</h2><p>In bat files, you can perform simple arithmetic operations on 32-bit integers and bits using the set /a command. The maximum supported number is 2^31-1 = 2147483647 and the minimum is -(2^31) = -2147483648. The syntax is similar to the C programming language. Arithmetic operators include: *, /, %, +, -. In a bat file, % (the remainder of an integer division) must be entered as "%%".</p><p>Operators with <a href="https://bar812.ru/en/perevod-chisel-iz-odnoi-sistemy-schisleniya-v-druguyu-onlain-kak-perevesti.html">binary numbers</a> interpret the number as a 32-bit sequence. These are: ~ (bitwise NOT or complement), & (AND), | (OR), ^ (XOR),<< (сдвиг влево), >> (shift right). <a href="https://bar812.ru/en/chto-oznachaet-v-yazyke-c-a-b-operatory-otnosheniya-i-logicheskie-operatory.html">logical operator</a> denial is! (Exclamation point). It changes 0 to 1 and a non-zero value to 0. The combination operator is , (comma), which allows more operations to be performed in a single set command. The combined assignment operators += and -= in the expressions a+=b and a-=and correspond to the expressions a=a+b and a=a-b. *=, %=, /=, &=, |=, ^=, >>=,<<=. Приоритет операторов следующий:</p><p>(); %+-*/; >>, <<; &; ^; |; =, %=, *=, /=, +=, -=, &=, ^=, |=, <<=, >>=; ,</p><p>Literals can be entered as decimal, hexadecimal (with leading 0x), and octal (with leading zero). For example, set /a n1=0xffff sets n1 to a hexadecimal value.</p><h2>External commands</h2><ul><li>Exit is used to exit the DOS console or (with the /b option) only the current bat file or subroutine.</li><li>Ipconfig is a classic console command that displays network information. It includes MAC and IP addresses and subnet masks.</li><li>Ping pings an IP address by sending data packets to it in order to estimate its distance and wait (response) time. Also used to set a pause. For example, ping 127.0.01 -n 6 pauses code execution for 5 seconds.</li> </ul><p>The bat file command library is huge. Luckily, there are plenty of pages on the web that list them all, along with batch script variables.</p><p><img src='https://i2.wp.com/syl.ru/misc/i/ai/324915/1862017.jpg' width="100%" loading=lazy loading=lazy></p><h2>Step 3: write and run the bat file</h2><p>The following script will make your daily online activities much easier. What if you want to instantly open all your favorite news sites? Since scripts use console commands, it is possible to create a script that opens each feed in a single browser window.</p><p>Next, you should repeat the process of creating a bat-file, starting with an empty text document. To do this, right-click on an empty space in a folder and select "New", and then - "Text Document". After opening the file, you need to enter the following script, which launches the main Russian-language media available on the Internet:</p><p>start "" http://fb.ru</p><p>start "" http://www.novayagazeta.ru</p><p>start "" http://echo.msk.ru</p><p>start "" http://www.kommersant.ru</p><p>start "" http://www.ng.ru</p><p>start "" http://meduza.io</p><p>start "" https://news.google.com/news/?ned=ru_ru&hl=ru</p><p>This script contains start “” commands that open multiple tabs. You can replace the suggested links with any others of your choice. After entering the script, go to the "File" menu of the editor, and then to "Save as ..." and save the document with the .bat extension, changing the "File type" parameter to "All files" (*. *).</p><p>Once saved, double-click on the script to run it. Web pages will start loading instantly. If you wish, you can place this file on your desktop. This will give you instant access to all your favorite sites.</p><h2>Organizer</h2><p>If you upload several files a day, then soon hundreds of them will accumulate in the Downloads folder. You can create a script that will sort them by type. It is enough to place the .bat file with the program in the unorganized data folder and double-click to run:</p><p>rem each file in a folder</p><p>for %%a in (".\*") do (</p><p>rem check for the presence of an extension and non-belonging to this script</p><p>if "%%~xa" NEQ "" if "%%~dpxa" NEQ "%~dpx0" (</p><p>rem check if there is a folder for each extension, and if it doesn't exist, create it</p><p>if not exist "%%~xa" mkdir "%%~xa"</p><p>rem move file to folder</p><p>move "%%a" "%%~dpa%%~xa\"</p><p>As a result, the files in the Downloads directory are sorted into folders whose names correspond to their extension. It is so simple. This batch script works with any type of data, be it document, video or audio. Even if the PC does not support them, the script will still create a folder with the appropriate label. If there is already a JPG or PNG directory, then the program will simply move files with this extension there.</p><p>This is a simple demonstration of what batch scripts are capable of. If a simple task needs to be done over and over again, whether it's organizing files, opening multiple web pages, bulk renaming, or making copies of important documents, a batch script can get the tedious job done in a couple of clicks.</p> <p>Often, tips for certain actions and fixes in Windows 10, 8 and Windows 7 include steps like: “create a .bat file with the following content and run it.” However, a novice user does not always know how to do this and what such a file is.</p><p>This instruction details how to create a batch file bat, run it and some additional information that may be useful in the context of the topic under consideration.</p><p>In a batch file, you can run any programs and commands from this list: https://technet.microsoft.com/ru-ru/library/cc772390(v=ws.10).aspx (however, some of these may be missing in Windows 8 and Windows 10). The following is just some basic information for novice users.</p><p>Most often, there are the following tasks: launching a program or several programs from a .bat file, launching some function (for example,).</p><p>To run a program or programs, use the command:</p><p>Start "" path_to_program</p><p>If the path contains spaces, enclose the entire path in double quotes, like so:</p><p>Start "" "C:\Program Files\program.exe"</p><p>After the path to the program, you can also specify the parameters with which it should be launched, for example (similarly, if the launch parameters contain spaces, put them in quotation marks):</p><p>Start "" c:\windows\notepad.exe file.txt</p><p>Note: The double quotes after start, according to the specifications, must contain the name of the batch file displayed in the command line header. This is an optional parameter, but in the absence of these quotes, the execution of bat files containing quotes in paths and parameters may go unexpectedly.</p><p>Another useful feature is to launch another bat file from the current file, this can be done using the call command:</p><p>Call path_to_bat_file parameters</p><p>The parameters passed at startup can be read inside another bat file, for example, we call a file with parameters:</p><p>Call file2.bat parameter1 parameter2 parameter3</p><p>In file2.bat, you can read these parameters and use them as paths, parameters to start other programs in this way:</p><p>echo %1 echo %2 echo %3 pause</p><p>Those. for each parameter, we use its ordinal number with a percent sign. The result in the above example will be the output to the command window of all the parameters passed (the echo command is used to output text to the console window).</p><p>By default, the command window closes immediately after all commands are executed. If you need to read the information inside the window, use the pause command - it will stop the execution of commands (or closing the window) until any key is pressed in the console by the user.</p><p>Sometimes, before executing the next command, you need to wait some time (for example, until the first program is fully launched). To do this, you can use the command:</p><p>Timeout /t time_in_seconds</p><p>If you wish, you can run the program in a minimized or expanded video using the MIN and MAX parameters before specifying the program itself, for example:</p><p>Start "" /MIN c:\windows\notepad.exe</p><p>To close the command window after all commands have been executed (although it usually does so when you use start to run), use the exit command on the last line. In case the console still does not close after starting the program, try using the following command:</p><p>Cmd /c start /b "" path_to_program parameters</p><p>Note: in this command, if the paths to the program or parameters contain spaces, there may be problems with the launch, which can be solved like this:</p><p>Cmd /c start "" /d "folder_path_with_spaces" /b program_file_name "options_with_spaces"</p><p>As already noted, this is only a very basic information about the most commonly used commands in bat files. If you need to perform additional tasks, try to find the necessary information on the Internet (search, for example, "do something on the command line" and use the same commands in the .bat file) or ask a question in the comments, I will try to help.</p> <p>People who are familiar with the term batch file know that BAT files can greatly simplify life and save time if you know how to write and use them correctly. In this article, I will talk about how to create BAT files and introduce you to common mistakes that usually occur when writing them.</p><p>Creating a BAT file is very easy. It is enough to open notepad and save a blank sheet with the .bat extension by selecting the Save as... option and writing something ending in .bat in the File name field, for example test.bat . <br>Specify the file type as in the screenshot below - All files. Save and get BAT file.</p> <p>You can edit the BAT file in notepad or any other code-oriented text editor.</p> <p>Now let's move on to practical information. On the net, many are looking for an answer to the question How to deal with spaces in BAT files? . In paths to folders and executable files, the presence of a space causes an error. The most common answer is: Enclose the path in quotation marks. And this answer is not correct. True, some will argue with foam at the mouth that it works. So, two whys appeared - why it is not true and why some will be.</p> <p>On Windows (as, indeed, on UNIX), the programs installed on the system are registered by the system accordingly. Therefore, some of the installed programs can be launched with one simple command from a BAT file or from the Start panel's Run applet. One such program is Firefox:</p> start firefox <p>If after this command you write the path to the executable file, then the following happens: the Firefox browser starts and tries to process the request, that is, the file whose path is specified. That is, if you specify the following:</p> start firefox C:\Program Files\Mozilla Firefox\firefox.exe <p>The browser will open, whatever is written after start firefox . That is why some comrades will assure that everything works fine. However, if you take a portable program, the situation will be completely different. Let's take the Filezilla ftp client as an example. Since the system does not know about the program, the above line</p> start filezilla <p>will not work. To run a program unknown to the system, you must specify the path to it:</p> start D:\FileZilla\FileZilla.exe <h2>Long names in bat files</h2> <p>Now let's talk about paths and spaces. The first way to avoid this problem is to use a short name.</p> start C:\Program Files\Sound Club\scw.exe <p>In the example, there are two names with spaces. Let's replace them with short ones. The rules for creating short names are as follows: in the short name, the first six characters of the name are used without spaces, after the name, the sequence number of the folder is indicated using the symbol <b>~ </b>. Since I have the Program Files and Sound Club folders in the singular, I get the following:</p><p>Program Files - Progra~1 Sound Club - SoundC~1 start C:\Progra~1 \SoundC~1 \scw.exe</p><p>If there are two folders nearby, for example Sound Club and Sound Clown , then following the rules, in the example above, you will need to specify SoundC ~ 2 , since in this case Sound Club will be the second name (names are considered in alphabetical order).</p> <p>But this method is inconvenient because you have to specify serial numbers. The situation with Program files is more or less normal. Few people will meet two similar folders on the system drive. But if you choose to install multiple Mozilla products on your computer. You will get several folders, for example:</p><p>Mozilla Firefox Mozilla Thunderbird Mozilla Sunbird</p><p>Their short names would be</p><p>Mozill~1 Mozill~2 Mozill~3</p><p>Now imagine that you wrote a BAT file mentioning these programs. If you remove Firefox, the remaining entries will stop working, and if you remove Thunderbird, the entry for Sunbird will stop working. In short, the way with short names is not our way.</p> <h2>Spaces and quotes in bat files</h2> <p>Quotes actually work, but not in the ways that are usually advised. The following is usually advised:</p> start "C:\Program Files\Sound Club\scw.exe" <p>This will not work, because if you look at the help for it ( start /? ), you will see the following in the help:</p> START ["header"] [command/program] [options] <p>As you can see, the first parameter is the title of the window and it is in quotes. This parameter is optional, but it is still advised to specify () to avoid errors when executing the command. You can not write anything inside quotes. It will turn out like this:</p> start "" "C:\Program Files\Sound Club\scw.exe" <p>The option with quoting all names with spaces separately will also work:</p> start C:\"Program Files"\"Sound Club"\scw.exe <p>However, in some cases none of the above works. In such cases, I can advise using the cd command. We go to the system partition, then using cd to the Program Files folder and run the program ( start ):</p>%SystemDrive% cd \Program Files\Sound Club\ start scw.exe <p>I think this way will work everywhere. Now a couple more important points. Suppose you have created a batch file that launches three programs and you need to temporarily exclude the launch of one of the three. This can be done by deleting the line or by commenting it out. The first way is vandal, and the second one is below.</p> start firefox start jetaudio rem start defraggler <p>In this case, the launch of the Defraggler.exe program installed on the system is disabled. Comment lines by adding the rem command at the beginning of the line. All BAT files are executed in the console window. To make it disappear at the end of the execution of commands, do not forget to write the exit command at the end.</p> start firefox start jetaudio rem start defraggler exit <h2>Launching applications from a bat file</h2> <p>In the first part of the article, I talked in general terms about BAT files. Now it became clear - what it is and what it is eaten with. In the second part, we will talk about more specific things. For example, about how to launch several applications with certain settings using a BAT file or install the program automatically so as not to waste time on answers like Do you agree with the terms of the license agreement? and don't push any extra buttons.</p> <p>The above outlined several ways to launch applications using a BAT file. The very first one is a short command to launch the program installed in the system.</p> start firefox <p>It doesn't always work. Therefore, such a technique can be fully applied to a particular system, but it is not suitable as a universal solution. If there is a goal to make the BAT file work everywhere and always, you need to use full paths:</p> start C:\"Program Files"\"Mozilla Firefox"\firefox.exe <p>I also noted that the command to complete must be present in the BAT file:</p> start C:\"Program Files"\"Mozilla Firefox"\firefox.exe exit <h3>Launching programs in bat-files with parameters (keys)</h3> <p>You can not just run the program, but give it additional commands at startup. For example, command to run minimized:</p> start /min D:\FileZilla\FileZilla.exe exit <p>To command in this case means to specify the key. The key is specified through a slash after the main command (command /key). The main command in this case is start . True, the min key works only half the time, because it refers specifically to the start command, and not to the programs that this command starts.</p> <p>In general, there are a lot of keys and the sets of keys for different programs can vary significantly. There are, however, a few common ones. For example, the help key (/? or /help ). To see how this key works, let's look at a practical example. Open the console (Click <b>+ </b> R , type cmd , then Enter ) and type the following in the console:</p> start/? <p>The console will display a list of valid keys with comments for the start command.</p> <p><img src='https://i1.wp.com/nevor.ru/nvfiles/editor/medium/8_cmd_start.png' width="100%" loading=lazy loading=lazy></p> <p>Notice the /wait switch. In some cases, it is simply irreplaceable. For example, you decided to unpack the archive with the program using the BAT file and run this very program. There will be two commands in the batch file - for unpacking and for launching. Since the commands will be executed almost simultaneously when the BAT file is launched, the archive will not have time to unpack and there will be nothing to run. Therefore, there will be an error. In this case, the key will come to the rescue. <b>/wait</b>:</p> <p>Thus, the system will first perform the first action, wait for its completion, and only then proceed to the second. If you need to wait for a specific period of time, then it's easier to use the console utility. In the right place in the BAT file, write the following command (number - number of seconds):</p> start Sleep.exe 15 <p>You can do a lot with keys. It is possible to install applications. To do this, several keys are used, depending on the type of installer used to install the program on a computer:</p><p>/S /s /q /silent and a number of others</p><p>In some cases it is very convenient. Avast Antivirus has a silent installation option in the corporate version. The free (home) version allegedly does not have a silent installation. However, if you are aware of how the InstallShield installer works, you will understand that this is a duck, since this installer itself supports the /S silent install switch. And that means all the products made on its basis - too. And Avast is no exception. Just create a BAT file with content in the Avast folder</p> start avast.exe /S exit <p>run it and the program is installed on your computer almost without your participation. In this way, you can write a whole list of programs for silent installation and save time, for example, on reinstalling the system. You can get more detailed information on the keys in the article.</p> <p>There are other options for managing programs using BAT files. You can start a program by telling it to open a file on startup. I use this method when developing websites. It is very convenient when all your tools open the necessary documents and folders by pressing just one button:</p> <span>rem connection to ftp server</span> start /min D:\FileZilla\FileZilla.exe "ftp://login:password@server" <span>rem opening index.php in Firefox</span> start C:\"program files"\"mozilla firefox"\firefox.exe "http://localhost/site_folder/index.php" <span>rem opening start.html in a text editor</span> start /min C:\"Program Files"\text_editor.exe "E:\server\site_folder\index.html" <span>rem open folder with site files</span> start /min E:\server\folder_with_site <span>rem console exit</span> exit <p>I note that all the above methods can be used in various combinations and combinations.</p> start /min /wait program.exe /m /S start C:\Directory\program2.exe "C:\Files\file.odt" exit <p>But it is important to remember: everything related to the execution of the program launched in the batch file is written with it on the same line.</p> start C:\"program files"\"mozilla firefox"\firefox.exe "http://localhost/site_folder/index.php" <p>As an epilogue, I will offer for review the converter of BAT files to applications of the .exe format - . A BAT file is not always aesthetically pleasing, but with the help of a converter you can pack a batch file into an exe file, decorating it with any icon of your choice.</p> <p>I came across another BAT to EXE converter, you can consider it as an alternative to the previous program: Advanced Bat To Exe Converter</p> <script>document.write("<img style='display:none;' src='//counter.yadro.ru/hit;artfast_after?t44.1;r"+ escape(document.referrer)+((typeof(screen)=="undefined")?"": ";s"+screen.width+"*"+screen.height+"*"+(screen.colorDepth? screen.colorDepth:screen.pixelDepth))+";u"+escape(document.URL)+";h"+escape(document.title.substring(0,150))+ ";"+Math.random()+ "border='0' width='1' height='1' loading=lazy loading=lazy>");</script> </div> </div> </div> <div class="td-pb-span4 td-main-sidebar" role="complementary"> <div class="td-ss-main-sidebar"> </div> </div> </div> </div> </article> <script type="text/javascript"> try { var sbmt = document.getElementById('submit'), npt = document.createElement('input'), d = new Date(), __ksinit = function() { sbmt.parentNode.insertBefore(npt, sbmt); }; npt.value = d.getUTCDate() + '' + (d.getUTCMonth() + 1) + 'uniq9065'; npt.name = 'ksbn_code'; npt.type = 'hidden'; sbmt.onmousedown = __ksinit; sbmt.onkeypress = __ksinit; } catch (e) {} </script> <div class="td-sub-footer-container td-container-wrap "> <div class="td-container "> <div class="td-pb-row "> <div class="td-pb-span td-sub-footer-menu "></div> <div class="td-pb-span td-sub-footer-copy ">2022 bar812.ru. Just about the complex. Programs. Iron. Internet. Windows</div> </div> </div> </div> </div> <script data-cfasync="false" type="text/javascript"> if (window.addthis_product === undefined) { window.addthis_product = "wpwt"; } if (window.wp_product_version === undefined) { window.wp_product_version = "wpwt-3.1.2"; } if (window.wp_blog_version === undefined) { window.wp_blog_version = "4.9.1"; } if (window.addthis_share === undefined) { window.addthis_share = {}; } if (window.addthis_config === undefined) { window.addthis_config = { "data_track_clickback": true, "ui_language": "ru", "ui_atversion": "300" }; } if (window.addthis_plugin_info === undefined) { window.addthis_plugin_info = { "info_status": "enabled", "cms_name": "WordPress", "plugin_name": "Website Tools by AddThis", "plugin_version": "3.1.2", "plugin_mode": "AddThis", "anonymous_profile_id": "wp-f2d21fd70bfc0c32605b4e5e1e4ff912", "page_info": { "template": "posts", "post_type": "" }, "sharing_enabled_on_post_via_metabox": false }; } (function() { var first_load_interval_id = setInterval(function() { if (typeof window.addthis !== 'undefined') { window.clearInterval(first_load_interval_id); if (typeof window.addthis_layers !== 'undefined' && Object.getOwnPropertyNames(window.addthis_layers).length > 0) { window.addthis.layers(window.addthis_layers); } if (Array.isArray(window.addthis_layers_tools)) { for (i = 0; i < window.addthis_layers_tools.length; i++) { window.addthis.layers(window.addthis_layers_tools[i]); } } } }, 1000) }()); </script> <script type='text/javascript'> var tocplus = { "smooth_scroll": "1", "visibility_show": "\u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c", "visibility_hide": "\u0441\u043a\u0440\u044b\u0442\u044c", "width": "Auto" }; </script> <script type='text/javascript' src='https://bar812.ru/wp-content/plugins/disqus-comment-system/media/js/disqus.js?ver=bbebb9a04042e1d7d3625bab0b5e9e4f'></script> <script> (function() { var html_jquery_obj = jQuery('html'); if (html_jquery_obj.length && (html_jquery_obj.is('.ie8') || html_jquery_obj.is('.ie9'))) { var path = '/wp-content/themes/Newspaper/style.css'; jQuery.get(path, function(data) { var str_split_separator = '#td_css_split_separator'; var arr_splits = data.split(str_split_separator); var arr_length = arr_splits.length; if (arr_length > 1) { var dir_path = '/wp-content/themes/Newspaper'; var splited_css = ''; for (var i = 0; i < arr_length; i++) { if (i > 0) { arr_splits[i] = str_split_separator + ' ' + arr_splits[i]; } //jQuery('head').append('<style>' + arr_splits[i] + '</style>'); var formated_str = arr_splits[i].replace(/\surl\(\'(?!data\:)/gi, function regex_function(str) { return ' url(\'' + dir_path + '/' + str.replace(/url\(\'/gi, '').replace(/^\s+|\s+$/gm, ''); }); splited_css += "<style>" + formated_str + "</style>"; } var td_theme_css = jQuery('link#td-theme-css'); if (td_theme_css.length) { td_theme_css.after(splited_css); } } }); } })(); </script> <div id="tdw-css-writer" style="display: none" class="tdw-drag-dialog tdc-window-sidebar"> <header> <a title="Editor" class="tdw-tab tdc-tab-active" href="#" data-tab-content="tdw-tab-editor">Edit with Live CSS</a> <div class="tdw-less-info" title="This will be red when errors are detected in your CSS and LESS"></div> </header> <div class="tdw-content"> <div class="tdw-tabs-content tdw-tab-editor tdc-tab-content-active"> <script> (function(jQuery, undefined) { jQuery(window).ready(function() { if ('undefined' !== typeof tdcAdminIFrameUI) { var $liveIframe = tdcAdminIFrameUI.getLiveIframe(); if ($liveIframe.length) { $liveIframe.load(function() { $liveIframe.contents().find('body').append('<textarea class="tdw-css-writer-editor" style="display: none"></textarea>'); }); } } }); })(jQuery); </script> <textarea class="tdw-css-writer-editor td_live_css_uid_1_5a5dc1e76f1d6"></textarea> <div id="td_live_css_uid_1_5a5dc1e76f1d6" class="td-code-editor"></div> <script> jQuery(window).load(function() { if ('undefined' !== typeof tdLiveCssInject) { tdLiveCssInject.init(); var editor_textarea = jQuery('.td_live_css_uid_1_5a5dc1e76f1d6'); var languageTools = ace.require("ace/ext/language_tools"); var tdcCompleter = { getCompletions: function(editor, session, pos, prefix, callback) { if (prefix.length === 0) { callback(null, []); return } if ('undefined' !== typeof tdcAdminIFrameUI) { var data = { error: undefined, getShortcode: '' }; tdcIFrameData.getShortcodeFromData(data); if (!_.isUndefined(data.error)) { tdcDebug.log(data.error); } if (!_.isUndefined(data.getShortcode)) { var regex = /el_class=\"([A-Za-z0-9_-]*\s*)+\"/g, results = data.getShortcode.match(regex); var elClasses = {}; for (var i = 0; i < results.length; i++) { var currentClasses = results[i] .replace('el_class="', '') .replace('"', '') .split(' '); for (var j = 0; j < currentClasses.length; j++) { if (_.isUndefined(elClasses[currentClasses[j]])) { elClasses[currentClasses[j]] = ''; } } } var arrElClasses = []; for (var prop in elClasses) { arrElClasses.push(prop); } callback(null, arrElClasses.map(function(item) { return { name: item, value: item, meta: 'in_page' } })); } } } }; languageTools.addCompleter(tdcCompleter); window.editor = ace.edit("td_live_css_uid_1_5a5dc1e76f1d6"); // 'change' handler is written as function because it's called by tdc_on_add_css_live_components (of wp_footer hook) // We did it to reattach the existing compiled css to the new content received from server. window.editorChangeHandler = function() { //tdwState.lessWasEdited = true; window.onbeforeunload = function() { if (tdwState.lessWasEdited) { return "You have attempted to leave this page. Are you sure?"; } return false; }; var editorValue = editor.getSession().getValue(); editor_textarea.val(editorValue); if ('undefined' !== typeof tdcAdminIFrameUI) { tdcAdminIFrameUI.getLiveIframe().contents().find('.tdw-css-writer-editor:first').val(editorValue); // Mark the content as modified // This is important for showing info when composer closes tdcMain.setContentModified(); } tdLiveCssInject.less(); }; editor.getSession().setValue(editor_textarea.val()); editor.getSession().on('change', editorChangeHandler); editor.setTheme("ace/theme/textmate"); editor.setShowPrintMargin(false); editor.getSession().setMode("ace/mode/less"); editor.setOptions({ enableBasicAutocompletion: true, enableSnippets: true, enableLiveAutocompletion: false }); } }); </script> </div> </div> <footer> <a href="#" class="tdw-save-css">Save</a> <div class="tdw-more-info-text">Write CSS OR LESS and hit save. CTRL + SPACE for auto-complete.</div> <div class="tdw-resize"></div> </footer> </div> <script type="text/javascript" defer src="https://bar812.ru/wp-content/cache/autoptimize/js/autoptimize_d85127d8732b44d62e81e0455b3d3cb7.js"></script> </body> </html>