Showing posts with label calculations. Show all posts
Showing posts with label calculations. Show all posts

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. 

Sunday, May 15, 2011

Checking File Size in Batch Files

It's sometimes necessary to check the size of a given file. For example, if you are to delete too big files on your hard drive or split single file into many parts. As usual, batch files are powerful enough to perform such task. The example below shows how to check batch file size (file is called 1.txt) and exit the script if the size is equal to 100 Kb.
for %%a in (1.txt) do if %%~za EQU 102400 goto :EOF
You can use this example in scripts that you create with help of our award-winning program designed to write batch files.

Thursday, February 17, 2011

Batch Calculator

Here is a small example of 'Set' command usage. The script below is a calculator, and as far as you can see we do almost nothing to calculate anything - just take the user's input data and send it to 'set' command that makes all calculations. Of course, this example is not a serious calculator, but it shows a very useful way to make some operations in batch scripts. You can easily include this code into batch files that you create with the help of our powerful batch files editor Dr.Batcher.
@ echo off
:begin
Cls
Title Calculator
Color 71
Echo Enter the expression:
Set /P exp=
Set /A result=%exp%
Echo Your expression: %exp%
Echo Result: %result%
Pause>nul
goto begin

Translate