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. 

Translate