Friday, October 25, 2013

Commands'Section at Dr.Batcher Web Site

We are glad to introduce the new section of drbatcher.com. It is called Batch File Commands and here you can find a lot of information about the most commonly used batch file commands.
If you have any suggestions or improvements please contact us.
Also we are glad to announce that we have started woring on Dr.Batcher 3.0. Hope we'll be able to release the beta version of it up to the New Year.

Tuesday, September 3, 2013

Using PUSHD and POPD Commands in Batch Files

There are two really handy commands that are not very commonly used by the batch files' developers. They are named PUSHD and POPD. If you are familiar with Assembler, you may guess what these commands do. The first one stores the folder name (pushes directory) in some internal stack, and the second one brings it back (pops directory). Note that you can put several folders to the stack and them restore them in the reversed order (LIFO - last in, first out). It is much handier sometimes to use PUSHD/POPD instead of using special variables to store folders like in other programming languages.
Here's small example of using these commands:
ECHO Performing some file manipulations in one directory
REM Here are manipulations
REM Remembering this folder
PUSHD
CD AnotherFolder
ECHO Performing some file manipulations in another directory
REM Here are manipulations
REM Remembering this folder
PUSHD
CD YetAnotherFolder
ECHO Performing some file manipulations in this directory
REM Here are manipulations
REM Deleting temporary files in YetAnotherFolder
POPD
REM Deleting temporary files in AnotherFolder
POPD
REM Deleting temporary files in the first folder
REM That's all
So you should remember about these commands while you create batch files.
We kindly remind that Dr.Batcher is the best program to create batch file, both .BAT and .CMD, try it if haven't tried it yet. 

Tuesday, August 6, 2013

Using Quotes in Batch Files

It is likely that using quotes is a hard topic for everyone who strats learning batch programming. We'll try to clarify this question a bit.
Quotes is just the way to pass the parameters containing spaces. Let's see an example:
DIR c:\Program Files
It seems that it's all right, and we'll list files and folders from Program Files directory. But this is wrong opinion because the space in batch files is delimiter for parameters passing to the batch command.To pass the single argument to the DIR command you should quote it:
DIR "c:\Program Files"
Quotes is not the part of the folder name. They only let the command know that space is the part of this name.
We kindly remind that Dr.Batcher is the best program to create batch file, both .BAT and .CMD, try it if haven't tried it yet. 

Wednesday, July 17, 2013

Why to Use Variables in Batch Files?

When you write your own batch file, you usually have no need to use  many variables in your code. Batch files with all their GOTOs and old syntax make you hard-code all needful data directly into the batch file instead of trying to make your code a bit flexible. Is this a good practice? We suppose it isn't.
Once written, code with variables can be easily copied to many different new batch scripts. Any you have no need to waste time trying to understandd your old code. Using variables makes your code much more readable and reusable, and this is the main advantage of using them.
The most useful tip is to use system variables instead of hard-coding different Windows folders. For example, it's better to use %SystemRoot% instead of writing directly "c:\Windows". You can watch all system variables by running SET command without any parameters. You can also see all actiual values of system variables in Dr.Batcher. Tools -> Environment Variables:
We kindly remind that Dr.Batcher is the best program to create batch file, both .BAT and .CMD, try it if haven't tried it yet.

Friday, July 12, 2013

Hot to Clean Thumbnail Cache

Thumbnails are the great time-savers helping us to find the needful documents (especially images) when we need them. But still thumbnails need a lot of disk space because Windows stores them in a cache in order to save time needed to generate them. And when disk space is quite law, you need to clean thumbnail cache. Here is a  simple batch file that can help you in this task:
@ECHO off
TITLE Cleaning Thumbnails...
ECHO ***This Batch File Clears The Thumbnail Cache***
ECHO Cleaning Now...
GOTO s
:s
DEL /F /Q %userprofile%\AppData\Local\Microsoft\Windows\Explorer\*.db
ECHO Thumbnail Cache Successfully Cleared!
PAUSE
We kindly remind that Dr.Batcher is the best program to create batch file, both .BAT and .CMD, try it if haven't tried it yet. 

Tuesday, July 2, 2013

Delete All Files Except Specified Ones

Sometimes it is neccessary to delete all files in a folder except some of them that are still useful. Here is small batch script that lets you delete all files except the specified ones. The parameter you pass to  this  script is the wildcard of files you want to leave.
@ECHO OFF
MD SAVE
XCOPY %1 SAVE > NUL

ECHO Y | DEL . > NUL
MOVE SAVE\*.* . > NUL
RD SAVE
ECHO Done
We kindly remind that Dr.Batcher is the best program to create batch file, both .BAT and .CMD, try it if haven't tried it yet. 

Thursday, June 27, 2013

Batch File to Calculate Disk Space

If you need to calculate disk space used by a directory or by some files, the batch file below can be useful for you. If you call it with the parameter /d it lists each subdirectory. Without any parameters it just prints the total number of files and bytes.
@echo off
if not '%1=='/d goto howmuch1
dir /a-d /s|find "i"|find /v "Volume"|more
goto done
:howmuch1
dir /a-d /s|find "file(s)"|sort /r|find /n "f"|find "[1]"

We kindly remind that Dr.Batcher is the best program to create batch file, both .BAT and .CMD, try it if haven't tried it yet. 

Thursday, June 13, 2013

Batch File to Kill a Process

Sometimes it is necessary to kill a process from a batch file. Here is a small script that shows you batch file to kill a process:
tasklist|find /i "process.exe">nul & if errorlevel 1 (echo No such process!) else (taskkill /f /im process.exe /t)
You need to replace process.exe with the name of your process to be killed. You can find additional information on the commands taskkill and tasklist on Microsoft website.
We kindly remind that Dr.Batcher is the best program to create batch file, both .BAT and .CMD, try it if haven't tried it yet. 

Wednesday, June 5, 2013

Path to Microsoft Office Folder

If you want to perform some manipulations with MS Office or just check the existance of this software on a computer running Windows, you don't have to find the path to Microsoft Office folder manually. All you need to do is running quite a small batch script that you can see below:
for /L %%i in (15,-1,7) do call :GetPath %%i
goto :end
:GetPath
reg query HKLM\Software\Microsoft\Office\%1.0\Common\InstallRoot /v Path
if errorlevel 1 goto :end
acregl.exe "%TEMP%\SetPath.cmd" OFFICE_PATH HKLM\Software\Microsoft\Office\%1.0\Common\InstallRoot Path ""
call "%TEMP%\SetPath.cmd"
del "%TEMP%\SetPath.cmd" 2>&1
:end

As far as you can see, this script searches for path to Microsoft Office folder for different versions of Microsoft Office, from 7.0 (MS Office 97) to 15 (MS Office 2013). For future versions you should just increase the starting number in 'for' loop at the first  line of this script.
After executing this script you'll find path to Microsoft Office folder in OFFICE_PATH variable.
Also you need to place acregl.exe to the folder with your batch file before executing this script. You can find it in your 'Windows' folder on system drive.
We kindly remind that Dr.Batcher is the best program to create batch file, both .BAT and .CMD, try it if haven't tried it yet. 

Sunday, June 2, 2013

How to Delete Files from the Specified List (Batch Script)

There is quite a common task for batch file programming which is called 'Deleting Files from Specified List'. It is not hard to perform this operation. Here is a small batch script that may help you with this task:
SET LstName=
FOR /F %%i in ('type %LstName%') do DEL %%i
PAUSE
The only thing you need to do is specifying your own files list. What is this list? It is is simple text file with one name of file to be removed per one line. For example:
c:\Temp\*.*
d:\Dir\Data1.tmp
e:\Work\Temp\*.dat
etc.
We kindly remind that Dr.Batcher is the best program to create batch file, both .BAT and .CMD, try it if haven't tried it yet. 

Wednesday, May 29, 2013

Calculate Folder Size in Batch File

It is neccessary sometimes to calculate the size of a certain folder in batch file. Though it is easy to see the size of a folder in Windows, calculating it in a batch script can be considered quite a complicated task. This small script will help you with this task:
@Echo Off
For /F "Tokens=3*" %%a In (
'Dir /-C C:\Temp ^| Find "files"') Do Echo The C:\Temp folder size = %%a
pause
Of course you should first change 'c:\Temp' to path to the folder which size you want to calculate.
We kindly remind that Dr.Batcher is the best program to create batch file, both .BAT and .CMD, try it if haven't tried it yet. 

Wednesday, May 22, 2013

Dr.Batcher 2.3.2 Is Out!

We are glad to announce Dr.Batcher 2.3.2 - the new version of award-winning tool designed to create batch files. Here is  the list  of new features and improvements in this version:
  • Highlighting labels in source code
  • Support for dragging commands from left panel to souce code in Professional mode
  • 'Never Ask Again' option in 'Delete Command' prompt in Simple mode
  • Highlihting opening and closing brackets in Professional mode
  • Lots of bugfixes
Download Dr.Batcher from official Web site.

Tuesday, May 14, 2013

Batch Files GTR and LSS: How to Compare Numbers in Batch Files

Comparing numbers in batch files is not difficult. Usually  you don't need to compare numbers in batch files very often, but sometimes  it is neccessary. What do you need to do to compare two numbers in batch file?
There are two main operators that can help you compare numbers in batch file. They are named GTR and LSS. The first command says whether the first number is greater than the second one, the second command says whether the first number is less than the second one. Here are the examples of their usage:
SET Nmbr1=100
SET Zero=0
IF %Nmbr1% GTR %Zero%   ECHO Greater than zero
Or:
SET Nmbr2=10
SET Hundred=100
IF %Nmbr2% LSS %Hundred%   ECHO Less than one hundred
You can make them nested:
IF %Nmbr2% LSS %Hundred% ( IF %Nmbr1% GTR %Zero% (ECHO  Greater than zero but less than one hundred)
We kindly remind that Dr.Batcher is the best program to create batch file, both .BAT and .CMD, try it if haven't tried it yet. 

Monday, May 6, 2013

Difference between Call and Start

You may know that you can run a program or a batch file from your own batch file with the help of commands 'start' and 'call'. Both of them are used quite often, but what's the difference between them?
'Call' command pauses the execution of your batch file until the end of working of the called program or script. You can see it by creating a test batch file with a single 'pause' command. Save this test script as 'tst.cmd' and create batch file with text 'call tst' (no quotes). You'll see that your batch file waits for the end of execution of tst.cmd.
'Start' command starts the program or script in independent mode.  Change 'call' in your batch file to 'start'. You'll see that the main batch file closes its window while 'tst.cmd' is still running.
We kindly remind that Dr.Batcher is the best program to create batch file, both .BAT and .CMD, try it if haven't tried it yet. 

Monday, April 29, 2013

How to Clean Temp Folders

We have already discussed how to clean temp folders in this blog. But there are more ways to clean temp folders, and here we'll show one more of them. You can see the batch file that will clean all temporary files on your computer below.

cd %windir%\Temp
del /s /q %windir%\Temp\*.*
md %windir%\Temp


cd %userprofile%\AppData\Local
del /F /S /P %userprofile%\AppData\Local\*.tmp
md %userprofile%\AppData\Local

cd %userprofile%\AppData\Local\Temp
del /F /S /P %userprofile%\AppData\Local\Temp\*.tmp
md %userprofile%\AppData\Local\Temp

cd %userprofile%\AppData\LocalLow
del /F /S /P %userprofile%\AppData\LocalLow\*.tmp
md %userprofile%\AppData\LocalLow

cd %userprofile%\AppData\Roaming
del /F /S /P %userprofile%\AppData\Roaming\*.tmp
md %userprofile%\AppData\Roaming


This batch file is suitable for Windows Vista and newer operating systems.
We kindly remind that Dr.Batcher is the best program to create batch file, both .BAT and .CMD, try it if haven't tried it yet. 

Thursday, April 25, 2013

Batch File to Send a File to All Computers in Network

Sending a single file to all computers in the network is quite a common task for Windows system administrators. It is handy to have a script that will automate this process. Here is the batch file to send a file to all computers in network:
REM Mass File Sender
REM Sends the specified file to all computers
REM in your network. 


REM Don't forget to replace "compyfile" before
REM executing this script.
SET copyfile=SomeFile.ext
net use S: /delete /y
@net view  | @FOR /F "tokens=1" %%c in ('@find "\\" ') do (
net use S: %%c\c$\bin
COPY %copyfile% S:\ /y
net use S: /delete /y
)

You should just change 'copyfile' to the path to the needful file before executing this script. You should also remember that sending large files can make your network very slow.
We kindly remind that Dr.Batcher is the best program to create batch file, both .BAT and .CMD, try it if haven't tried it yet. 

Monday, April 22, 2013

.BAT or .CMD?

What's the difference between the extensions of batch files? As you may know, they can have extensions .BAT or .CMD. What's the 'right' extension for today?
BAT files were known since the early DOS age, and you can run BAT file both from DOS, old Windows (3.1, 95, 98...) and modern Windows up to Windows 8. CMD files were introduced as the replacement for BAT files. We still call them 'batch files', but it is more convenient to call them 'command files'. The old versions of Windows and of couse MS-DOS don't recognize these files as executable ones.
So it is better to save the files that you want to run under old operating systems with .BAT extension, and all others save with .CMD extension.
We kindly remind that Dr.Batcher is the best program to create batch file, both .BAT and .CMD, try it if haven't tried it yet.

Friday, April 19, 2013

Remove Files Completely

It is necessary sometimes to remove files completely from a certain folder. It is handy to perform such action with the help of batch files.
Here you can find a small and useful script that might help you to clear the folder from all folders and files inside:
@echo off
echo ***Warning***
echo ***This Will Delete All Files and Folders Permanately!***
echo ***You Will Be Prompted To Confirm File Deletion...***
echo ***Verify All Files Before Deletion...***
del /P /S %1
pause

How to use this script? Save it (for example, as clearfiles.bat) and run from the command prompt with the folder to be cleaned as a parameter. For example:
clearfiles d:\Work\Old\Trash
We kindly remind that Dr.Batcher is the best program to create batch file, try it if haven't tried it yet.

Monday, April 15, 2013

Dr.Batcher 2.3.1 Is Available

We are glad to introduce Dr.Batcher 2.3.1 - the new version of award-winning tool designed to create batch file. In this version you'll find:
  • Checking for existance of files in list while adding to EXE or backup
  • Parsing '^' character in a right way
  • Automatic update enhanced
  • Lots of small bugfixes
Download Dr.Batcher from official Web site.

Tuesday, April 2, 2013

Friday Bag Lunch: File Splitting and Combining



The only one who may not like Friday is the one who has to work on Saturday. I’m not used to working on Saturday and only fuss can spoil my Friday night. And it was fuss that I felt as soon as I’d set foot into my flat. Don’t think that there were lots of people. Rather! There was only my daughter, but she was getting ready for a party!!!
The light was on everywhere, on the floor in the hall there was a hair dryer with all kinds of combs and other dodgy things, in the nursery S60 were roaring “Death In Vegas” at full blast, something in the bathroom was soaking, an iron was warming on the kitchen table, all stove burners were on and something was boiling on them while the daughter herself was sitting at the computer, with another comb stuck in her hair.
“Hi!” – I shouted.
“Your hands around my throat” – the “Vegas” answered.
I felt like running out into the landing and killing the power supply at one go...
...If I had called my friends in time and our plan to go to play billiards hadn’t been ruined, then..
“Hi, Dad!” I heard a voice behind my back, turned around and was petrified. Have you ever tried to look a person in the eyes when these eyes are totally different?
“What’s wrong with your eye?”
“Which one? The painted or the other one?”
“I see.”
“If you’re hungry, salads will be ready soon and you can help yourself a bit”
“What do you mean: help yourself a bit?”
“I’ll take the rest with me. The girls told me to cook salads”
I needed to hide somewhere! The only thing I could do is to lock myself up in my room and turn the TV on.
“Dad, will you help me with burning a video CD?”
“What do you mean: help you? You know how to burn CDs”
“But it’s too large – almost 2 gigabytes. It needs to be written on 2 CDs and I don’t know how to do it.”
I had no thought of teaching my daughter in such conditions, but I’d nowhere to go.
Having seated myself at the computer and on legal grounds turned the music off, I started working my salads off.
“Actually, it’s a very simple task. You can split a movie into parts by Total Commander. But there might be problems with putting these parts together.
“Daddy, you’re so clever! What problems you may have?”
“Not me, but you! Or the one who is in charge of computers at your party.”
“Rick is. And it was he who asked me to bring this movie. He’s always good at everything. You just help me burn the film, and he’ll puzzle everything out.”
“I doubt it. I’ve seen these know-alls. To know how to solve a problem you have to face it once at least.”
“And what kind of problem it may be?”
“The question is if he has Total Commander on his computer. If he has, then it won’t be difficult to reassemble the movie. If he doesn’t have Total Commander, then it will be hard for me to explain to him, and especially to you, how to do this. The only option is to write a detailed instruction down on a sheet of paper or into a text file.
“Daddy, you’re great! Of course, do it! And I’ll go into the kitchen to get the salads done”.
“That’s a heck of a lesson.”- I thought. “You teach me here and I’ll go do other things...”
The music started booming again, but I had nowhere to go and got down to my work. But in order not to return to this question, I decided to make up not a brief but a detailed instruction for my daughter and her friend. That’s what came out.
File splitting and combining
File splitting may be necessary in cases when the size of a storage medium (a floppy disk, CD...) is smaller than the size of a file. We will carry out this operation by Total Commander. It’s a good idea to move the file into a different folder (so that a novice user will see the result of the operation) and open it both in the left and the right windows (otherwise the parts will be copied to the folder opened in the opposite window). Select the file (or just place the cursor on it) and choose “Split File” in the “File” menu (fig. 1). Then choose the size of the parts (in our case – matrixes of 700 Mb each) and click “Ok”. In the folder you will see the files of the parts (their extensions will be .001, .002, ...) and a .crc-file containing the information about the source file (its name, size and checksum).
It’s better to copy all the three files to the matrixes. Free space is more likely to be on a disk with the last part, so you may write the crc-file just there.
File combining
After copying all the files to a hard drive of another computer, to combine them with the help of Total Commander you just need to press Enter on the .crc file or choose “Combine” in the “File” menu. In doing so the file will be combined in a folder opened in the opposite window.
Failing Total Commander on your computer, you can combine the file out of its parts by using the copy function in command line or create a bat-file (a batch file which will contain the same copy command.)
Copy command settings
The copy command will be as follows:
copy /b movie.001 + movie.002 movie.avi
(The key /b means binary copy).
And it is this line that is obligatory in a bat-file.
The bat-file can be run directly from the explorer.
Bat-file creation
You can create a bat-file in Total Commander by pressing the buttons “Shift” + F4” or in a simple Notepad. When naming the file, you must change its extension into .bat. But the most comfortable way to create batch file is tool called Dr.Batcher.
This file will consist of only one line with a copy command (see above).


I reread the text once again. All details seemed to have been mentioned, but somehow I thought it would be right to write the finished bat-file to the second matrix along with the instruction. That would be more effective. Friday night is not the best time for study. Especially, at parties.
I left the computer to burn the CD and went to tell my daughter about the result of my work. Having heard the welcome news, she flashed a glance at me with the already-equally-painted eyes and said, shouting the hair dryer down:
“Thanks, Dad! Maybe you’ll burn for me some music too?”
“No way, you can deal with it by yourself, and I’ll go eat your salads”.
The salads were delicious, and the mood suited the Friday night again.
Roger Vadey,

Monday, March 25, 2013

Clean AVG Temporary Files via Batch File

AVG is a great free antivirus quite popular among the users of Dr.Batcher. You can find it here. But as every software, it leaves sometimes some temporary files that should be cleaned manually by its user. Batch files are the best way to clear AVG temporary files.
Here is a small batch file that will help you to clean AVG temporary files:
CD "C:\Program Files (x86)\AVG\AVG8\"
avgcfgex.exe /command=19
CD C:\ProgramData\avg8\scanlogs
DEL C:\ProgramData\avg8\scanlogs\*.* /s /q
MD C:\ProgramData\avg8\scanlogs
CD C:\ProgramData\avg8\update\backup
DEL C:\ProgramData\avg8\update\backup\*.* /s /q
MD C:\ProgramData\avg8\updata\backup
ECHO Successfully Deleted All AVG Temp Update Files...
PAUSE

We kindly remind that Dr.Batcher is the best program to create batch file, try it if haven't tried it yet.

Translate