iceberg Posted July 12, 2008 Share Posted July 12, 2008 hi guys, sorry but i can't think properly for the time being..... would appreciate if someone can help me out here with some logics.... #include <Date.au3> $DSLog = @ScriptDir & "\Drivespace.log" $ini = @ScriptDir & "\settings.ini" $var = DriveGetDrive("FIXED") If Not @error Then For $i = 1 To $var[0] $Size = Round(DriveSpaceTotal($var[$i]) / 1024) $Freespace = Round(DriveSpaceFree($var[$i]) / 1024) $Usedspace = ($Size - $Freespace) $Percent = Round($Freespace / $Size * 100) $Percent2 = Round($Usedspace / $Size * 100) FileWrite($DSLog, $var[$i] & "\" & " Freespace: " & $Freespace & " GB (" & $Percent & "%)" & @TAB & "Usedspace: " & $Usedspace & " GB (" & $Percent2 & "%) " & " on " & _Now() & @CRLF) If $Percent < IniRead($ini, "drivespace", "percentage", "NotFound") Then If IniRead($ini, "drivespace", $var[$i] & "record", "NotFound") < $Percent Then IniWrite($ini, "drivespace", $var[$i] & "record", $Percent) Test() EndIf Else IniWrite($ini, "drivespace", $var[$i] & "record", "0") EndIf Next FileWrite($DSLog, @CRLF & @CRLF) EndIf Func Test() MsgBox(0, "Drive " & $var[$i] & " is running low", "Paging now...") EndFunc ;==>Test what i wanna do is this : 1) if the hard disk freespace % is below the stated % in the ini file, it should perform the Test(). 2) When the script is run again and if the hard disk freespace % is the same as before or higher, it should not perform the Test(). Thanks. mouse not found....scroll any mouse to continue. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 12, 2008 Moderators Share Posted July 12, 2008 Ini functions that return a value that something other than boolean for success or failure, are returned as a string. ie... IniRead(...) < is a string. So in essence, what you are doing is: If 9 < "9" Then See anything wrong there? If 9 < Number(IniRead(...)) Then or If 9 < Int(IniRead(...)) Then "NotFound" certainly isn't a number muttley Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
iceberg Posted July 12, 2008 Author Share Posted July 12, 2008 so in other words....i cant be using IniRead...? if so, how else can i approach this? text file? mouse not found....scroll any mouse to continue. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 12, 2008 Moderators Share Posted July 12, 2008 (edited) so in other words....i cant be using IniRead...? if so, how else can i approach this? text file?I didn't say you couldn't use an Ini... I'm saying you have to make the value returned a number/integer wrapping it in either Number() or Int() as I showed you above. Edit: There does seem to be some backwards logic with strings and numbers, but I would never personally trust it. It's up to us as the coders to distinguish the data types correctly, and it shouldn't be left up to an interpreter to do so. To give you an example of what I mean, if your IniRead() fails, it returns a value of "NOTFOUND" Run this:If 9 > "NOTFOUND" Then MsgBox(64, "Example", "9 is greater than NOTFOUND") That's basically what you are telling the interpreter to do. Even though it's a string, it still has a numerical value. Edited July 12, 2008 by SmOke_N Thought I'd iterate some points. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 12, 2008 Moderators Share Posted July 12, 2008 #include <Date.au3> Global $DSLog = @ScriptDir & "\Drivespace.log" Global $ini = @ScriptDir & "\settings.ini" Global $n_ini_val, $var = DriveGetDrive("FIXED") If Not @error Then For $i = 1 To $var[0] $Size = Round(DriveSpaceTotal($var[$i]) / 1024) $Freespace = Round(DriveSpaceFree($var[$i]) / 1024) $Usedspace = ($Size - $Freespace) $Percent = Round($Freespace / $Size * 100) $Percent2 = Round($Usedspace / $Size * 100) FileWrite($DSLog, $var[$i] & "\" & " Freespace: " & $Freespace & " GB (" & $Percent & "%)" & @TAB & "Usedspace: " & $Usedspace & " GB (" & $Percent2 & "%) " & " on " & _Now() & @CRLF) $n_ini_val = Number(IniRead($ini, "drivespace", "percentage", "-1")) If $n_ini_val <> -1 And ($Percent < $n_ini_val) Then $n_ini_val = Number(IniRead($ini, "drivespace", $var[$i] & "record", "-1")) If $n_ini_val <> -1 And ($n_ini_val < $Percent) Then IniWrite($ini, "drivespace", $var[$i] & "record", $Percent) Test() Else MsgBox(16, "Error", "Function not called, inivalue was: " & $n_ini_val) EndIf Else IniWrite($ini, "drivespace", $var[$i] & "record", "0") EndIf Next FileWrite($DSLog, @CRLF & @CRLF) EndIf Func Test() MsgBox(0, "Drive " & $var[$i] & " is running low", "Paging now...") EndFunc ;==>TestTry that, I didn't look at anything other than Ini btw, I'm assuming you are doing everything else correctly. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
iceberg Posted July 12, 2008 Author Share Posted July 12, 2008 thanks lot for the assistance SmOke_N. i have another query.... [sectionName] C:=0 D:=0 how do I ensure that the above keys exists? If it doesn't, it must be created. can i do something like that..... Global $var = DriveGetDrive("FIXED") Global $ini = @ScriptDir & "\settings.ini" Global $tes = IniReadSectionNames($ini) For $i = 1 To $var[0] For $j = 1 To $tes[0] If $tes[$i] <> $var[$j] Then IniWrite($ini, "drivespace", $var[$j], $Percent) Next Next thanks. mouse not found....scroll any mouse to continue. Link to comment Share on other sites More sharing options...
iceberg Posted July 12, 2008 Author Share Posted July 12, 2008 (edited) ok now...that did NOT obviously worked for me..after much thinking I came up with this method...it works though....but not too sure if it is logical.... #include <Date.au3> Global $DSLog = @ScriptDir & "\Drivespace.log" Global $ini = @ScriptDir & "\settings.ini" Global $n_ini_num, $n_ini_val, $var = DriveGetDrive("FIXED") For $i = 1 To $var[0] $key = IniRead($ini, "drivespace", $var[$i], "-1") If $key = -1 Then IniWrite($ini, "drivespace", $var[$i], "0") Next If Not @error Then For $i = 1 To $var[0] $Size = Round(DriveSpaceTotal($var[$i]) / 1024) $Freespace = Round(DriveSpaceFree($var[$i]) / 1024) $Usedspace = ($Size - $Freespace) $Percent = Round($Freespace / $Size * 100) $Percent2 = Round($Usedspace / $Size * 100) FileWrite($DSLog, $var[$i] & "\" & " Freespace: " & $Freespace & " GB (" & $Percent & "%)" & @TAB & "Usedspace: " & $Usedspace & " GB (" & $Percent2 & "%) " & " on " & _Now() & @CRLF) $n_ini_val = Number(IniRead($ini, "drivespace", "percentage", "-1")) $n_ini_num = Number(IniRead($ini, "drivespace", $var[$i], "-1")) If ($Percent <= $n_ini_val) And ($n_ini_num <> $Percent) Then Test() EndIf IniWrite($ini, "drivespace", $var[$i], $Percent) Next FileWrite($DSLog, @CRLF & @CRLF) EndIf Func Test() MsgBox(0, "Drive " & $var[$i] & " is running low", "Paging now...") EndFunc ;==>Test Edited July 12, 2008 by iceberg mouse not found....scroll any mouse to continue. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now