DOS input from 2 files to get a percentage

October 27, 2011 at 14:54:05
Specs: Windows 7
putting it simply...

OK so I have 2 files each with a single number in it. I need to see if I can create a batch file that will import the number from each file, divide the nummber in file one from the number in file 2 and if that number is greater than 10 it will create a file under c:\temp stating it is greater than 10. Is this possible if so how.

See More: DOS input from 2 files to get a percentage

Report •

October 27, 2011 at 19:51:19
Please explain the meaning of , divide the nummber in file one from the number in file 2 and if that number is greater than 10 it will create .... etc.. One cannot divide from anything, do you mean to subtract?

If either number or the output contains floating point this cannot be achieved in pure batch scripting as batch scripting cannot handle floating point.

Is this homework?

Please come back & tell us if your problem is resolved.

Report •

October 28, 2011 at 06:49:08
trying to devise a simple solution at zero cost for work that will identify the change in disk space percent free and based on our needs if the change is over say 10% then my script will send an email to our group.

I have a script that will create a file every day with the drive percent free space and it is setup to only have the number no other information. so for example over 2 days I will have 2 files day1.txt and day2.txt and day1 will have the value 65 in it and day2 will have the value 45 in it. I am trying to pull those 2 numbers out of each file and subtract them to give me the change in percentage. in this example 65-45=20 so my script will send my group an alert. I have scripts fort everything but being able to pull in the values from 2 different files

Does this make sense? I was hoping I could pull the 2 values into my script and possibly using an IF statment to trigger the email IF value1-value2 GTR 10 "runemail-script"

I am not sure this is possible but thought I would ask. I could use VBscript too but I am just starting to google that option.


Report •

October 28, 2011 at 06:56:53
I am trying to use the same kind of scripts that I use to pull names from a file to run in a loop, I am thinking using 2 of those to get the variables and the loop would run the subtraction and email script

i.e. using 2 of these staments

For /F "tokens=1-10" %%i in ('TYPE %scriptpath%\value1.txt') Do CALL :bigloop %%i %%j %%k

For /F "tokens=1-10" %%i in ('TYPE %scriptpath%\value2.txt') Do CALL :bigloop %%i %%j %%k

IF %1-%2 GTR 10 C:\blat -t %mailto% -s "%COMPUTERNAME% Danger Will Robinson, Danger %date%" -server "" -f ""

Report •

Related Solutions

October 28, 2011 at 07:08:49
I found a method for my madness. Just needed sleep to clear my head.

@ECHO on


@FOR /F "tokens=1-3" %%n IN ('"WMIC LOGICALDISK GET Name,Size,FreeSpace | find /i "%1""') DO @SET FreeBytes=%%n & @SET TotalBytes=%%p

set baseline=40
set mailto=""

@SET /A TotalSpace=!TotalBytes:~0,-9!
@SET /A FreeSpace=!FreeBytes:~0,-10!
@SET /A TotalUsed=%TotalSpace% - %FreeSpace%
@SET /A PercentUsed=(!TotalUsed!*100)/!TotalSpace!
@SET /A PercentFree=100-!PercentUsed!
ECHO %PercentFree%

set var1=%percentfree%
set var2=%baseline%
set /a sum1=%var1%-%var2%
echo %sum1%
If %sum1% gtr 9 C:\tools\blatemail parameters.....


Report •

Ask Question