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. 

Translate