jslegers Posted September 12, 2008 Posted September 12, 2008 (edited) Hello, This is the third time my script is playing tricks on me. Here's the script. expandcollapse popup#include <Date.au3> ; Setting autoit options AutoItSetOption ( "TrayMenuMode", 1 ) HotKeySet ( "#{ESC}", "Quit" ) If IniRead ( @ScriptDir & "\" & "Defrag.ini", "General", "TrayIcon", 1 ) = 0 Then TraySetState ( 2 ) Else TraySetState ( 1 ) EndIf If IniRead ( @ScriptDir & "\" & "Defrag.ini", "General", "Optimize", 1 ) = 0 Then $Opt = 2 Else $Opt = 3 EndIf ; Determing language and setting variables If @OSLang = 0409 Then $StartAn = "Starting analyze of fragmentation at " $Analy = "Analyzing " $Start = "Starting defragmentation of " $Defrag = "Defragmenting " $NoDefrag = "No defragmentation needed for " $Drive = " drive." ElseIf @OSLang = 0413 Then $StartAn = "Start met de analyse van de fragmentatie om " $Analy = "Analiseren van de " $Start = "Starten van defragmenteren " $Defrag = "Defragmenteren van de " $NoDefrag = "Geen defragmentatie nodig van " $Drive = " schijf." EndIf $Varfragini = IniRead ( @ScriptDir & "\" & "Defrag.ini", "General", "FragmentedFiles", 100 ) $Vartimeini = IniRead ( @ScriptDir & "\" & "Defrag.ini", "General", "Timeout", 5 ) ;ConsoleWrite($Vartimeini & @LF) ; Adding x minutes to the current time $sTime = _DateAdd ( 'n', $Vartimeini, _NowCalc()) $sNewTime = _DateTimeFormat ( $sTime, 4 ) ; Setting Tray Icons options. TraySetToolTip ( $StartAn & $sNewTime ) ; Waiting for x minutes. Sleep ( $Vartimeini * 60000 ) $Vardrive = DriveGetDrive( "FIXED" ) If NOT @error Then For $i = 1 to $Vardrive[0] ; Analyzing drive. TrayTip ( "", $Analy & StringUpper ( $Vardrive[$i] ) & $Drive, 3, 1 ) $JkDefragCom = "C:\Program Files\Defrag\JkDefragCmd.exe" $JkParam = "-a 1 -l C:\Analyze_" & StringUpper ( StringTrimRight ( $Vardrive[$i], 1 )) & ".log " & $Vardrive[$i] ShellExecuteWait ( $JkDefragCom, $JkParam, "", "", @SW_HIDE ) $Log = FileReadLine ( "C:\Analyze_" & StringTrimRight ( $Vardrive[$i], 1 ) & ".log" ,18 ) $Ret = StringRegExp($Log, ": ([0-9]{0,})", 1, 1) ;FileDelete ( "C:\Analyze_" & StringTrimRight ( $Vardrive[$i], 1 ) & ".log" ) ConsoleWrite($Ret[0] & @LF) If $Ret[0] > $Varfragini Then ; Starting defragmentation of drive. TrayTip ( "", $Start & StringUpper ( $Vardrive[$i] ) & $Drive, 3, 1 ) Sleep ( 3000 ) TrayTip ( "", "", 0 ) TraySetToolTip ( $Defrag & StringUpper ( $Vardrive[$i] ) & $Drive ) $JkParam = "-a " & $Opt & " -d 1 -s 100 -f 1 -l C:\Defrag_" & StringUpper ( StringTrimRight ( $Vardrive[$i], 1 )) & ".log " & $Vardrive[$i] ShellExecuteWait ( $JkDefragCom, $JkParam, "", "", @SW_HIDE ) Else TrayTip ( "Status", $NoDefrag & StringUpper ( $Vardrive[$i] ) & $Drive, 10, 1 ) Sleep ( 3000 ) EndIf Next EndIf ; Function Quit to stop the script. Func Quit() ProcessClose ( "JkDefragCmd.exe" ) Exit EndFunc Here is the ini file : [General] FragmentedFiles=500 Timeout=0 TrayIcon=1 Optimize=1 And here is a piece of the analyze log file : 15:54:34 JkDefrag v3.36 15:54:34 Date: 2008/09/12 15:54:34 Windows version: v5.1 build 2600 Service Pack 3 15:54:34 Commandline argument '-a' accepted, optimizemode = 1 15:54:34 Commandline argument '-l' accepted, logfile = C:\Analyze_C.log 15:54:34 NtfsDisableLastAccessUpdate is active, ignoring LastAccessTime for SpaceHogs. 15:54:34 Processing 'c:' 15:54:34 Opening volume '\\?\Volume{e8f1f9b1-60cc-11dd-b040-806d6172696f}' at mountpoint 'c:' 15:54:34 Input mask: c:\* 15:54:35 Phase 1: Analyze 15:54:35 This is an NTFS disk. 15:54:45 Finished. 15:54:45 - Total disk space: 34356477952 bytes (31.9970 gigabytes), 8387812 clusters 15:54:45 - Bytes per cluster: 4096 bytes 15:54:45 - Number of files: 89795 15:54:45 - Number of directories: 5286 15:54:45 - Total size of analyzed items: 15630741504 bytes (14.5573 gigabytes), 3816099 clusters 15:54:45 - Number of fragmented items: 1827 (1.9215% of all items) My script checks by the ini file if this drive has to be defragmented. As you can see the number of fragmented items = 1827. In the ini file there is a limit of 500. So in the script it says If 1827 > 500 then defrag. But this doesn't work. If the value is below 1000 say 600 than I runs fine. Why does it has problems with numbers bigger than 1000 ? Could this line be faulty $Log = FileReadLine ( "C:\Analyze_" & StringTrimRight ( $Vardrive[$i], 1 ) & ".log" ,18 ) $Ret = StringRegExp($Log, ": ([0-9]{0,})", 1, 1)JkDefragCmd.exe Edited September 12, 2008 by jslegers
Bowmore Posted September 12, 2008 Posted September 12, 2008 Hello, This is the third time my script is playing tricks on me. Here's the script. expandcollapse popup#include <Date.au3> ; Setting autoit options AutoItSetOption ( "TrayMenuMode", 1 ) HotKeySet ( "#{ESC}", "Quit" ) If IniRead ( @ScriptDir & "\" & "Defrag.ini", "General", "TrayIcon", 1 ) = 0 Then TraySetState ( 2 ) Else TraySetState ( 1 ) EndIf If IniRead ( @ScriptDir & "\" & "Defrag.ini", "General", "Optimize", 1 ) = 0 Then $Opt = 2 Else $Opt = 3 EndIf ; Determing language and setting variables If @OSLang = 0409 Then $StartAn = "Starting analyze of fragmentation at " $Analy = "Analyzing " $Start = "Starting defragmentation of " $Defrag = "Defragmenting " $NoDefrag = "No defragmentation needed for " $Drive = " drive." ElseIf @OSLang = 0413 Then $StartAn = "Start met de analyse van de fragmentatie om " $Analy = "Analiseren van de " $Start = "Starten van defragmenteren " $Defrag = "Defragmenteren van de " $NoDefrag = "Geen defragmentatie nodig van " $Drive = " schijf." EndIf $Varfragini = IniRead ( @ScriptDir & "\" & "Defrag.ini", "General", "FragmentedFiles", 100 ) $Vartimeini = IniRead ( @ScriptDir & "\" & "Defrag.ini", "General", "Timeout", 5 ) ;ConsoleWrite($Vartimeini & @LF) ; Adding x minutes to the current time $sTime = _DateAdd ( 'n', $Vartimeini, _NowCalc()) $sNewTime = _DateTimeFormat ( $sTime, 4 ) ; Setting Tray Icons options. TraySetToolTip ( $StartAn & $sNewTime ) ; Waiting for x minutes. Sleep ( $Vartimeini * 60000 ) $Vardrive = DriveGetDrive( "FIXED" ) If NOT @error Then For $i = 1 to $Vardrive[0] ; Analyzing drive. TrayTip ( "", $Analy & StringUpper ( $Vardrive[$i] ) & $Drive, 3, 1 ) $JkDefragCom = "C:\Program Files\Defrag\JkDefragCmd.exe" $JkParam = "-a 1 -l C:\Analyze_" & StringUpper ( StringTrimRight ( $Vardrive[$i], 1 )) & ".log " & $Vardrive[$i] ShellExecuteWait ( $JkDefragCom, $JkParam, "", "", @SW_HIDE ) $Log = FileReadLine ( "C:\Analyze_" & StringTrimRight ( $Vardrive[$i], 1 ) & ".log" ,18 ) $Ret = StringRegExp($Log, ": ([0-9]{0,})", 1, 1) ;FileDelete ( "C:\Analyze_" & StringTrimRight ( $Vardrive[$i], 1 ) & ".log" ) ConsoleWrite($Ret[0] & @LF) If $Ret[0] > $Varfragini Then ; Starting defragmentation of drive. TrayTip ( "", $Start & StringUpper ( $Vardrive[$i] ) & $Drive, 3, 1 ) Sleep ( 3000 ) TrayTip ( "", "", 0 ) TraySetToolTip ( $Defrag & StringUpper ( $Vardrive[$i] ) & $Drive ) $JkParam = "-a " & $Opt & " -d 1 -s 100 -f 1 -l C:\Defrag_" & StringUpper ( StringTrimRight ( $Vardrive[$i], 1 )) & ".log " & $Vardrive[$i] ShellExecuteWait ( $JkDefragCom, $JkParam, "", "", @SW_HIDE ) Else TrayTip ( "Status", $NoDefrag & StringUpper ( $Vardrive[$i] ) & $Drive, 10, 1 ) Sleep ( 3000 ) EndIf Next EndIf ; Function Quit to stop the script. Func Quit() ProcessClose ( "JkDefragCmd.exe" ) Exit EndFunc Here is the ini file : [General] FragmentedFiles=500 Timeout=0 TrayIcon=1 Optimize=1 And here is a piece of the analyze log file : 15:54:34 JkDefrag v3.36 15:54:34 Date: 2008/09/12 15:54:34 Windows version: v5.1 build 2600 Service Pack 3 15:54:34 Commandline argument '-a' accepted, optimizemode = 1 15:54:34 Commandline argument '-l' accepted, logfile = C:\Analyze_C.log 15:54:34 NtfsDisableLastAccessUpdate is active, ignoring LastAccessTime for SpaceHogs. 15:54:34 Processing 'c:' 15:54:34 Opening volume '\\?\Volume{e8f1f9b1-60cc-11dd-b040-806d6172696f}' at mountpoint 'c:' 15:54:34 Input mask: c:\* 15:54:35 Phase 1: Analyze 15:54:35 This is an NTFS disk. 15:54:45 Finished. 15:54:45 - Total disk space: 34356477952 bytes (31.9970 gigabytes), 8387812 clusters 15:54:45 - Bytes per cluster: 4096 bytes 15:54:45 - Number of files: 89795 15:54:45 - Number of directories: 5286 15:54:45 - Total size of analyzed items: 15630741504 bytes (14.5573 gigabytes), 3816099 clusters 15:54:45 - Number of fragmented items: 1827 (1.9215% of all items) My script checks by the ini file if this drive has to be defragmented. As you can see the number of fragmented items = 1827. In the ini file there is a limit of 500. So in the script it says If 1827 > 500 then defrag. But this doesn't work. If the value is below 1000 say 600 than I runs fine. Why does it has problems with numbers bigger than 1000 ? Could this line be faulty $Log = FileReadLine ( "C:\Analyze_" & StringTrimRight ( $Vardrive[$i], 1 ) & ".log" ,18 ) $Ret = StringRegExp($Log, ": ([0-9]{0,})", 1, 1) The problem is probably because the values you are comparing are strings. Try this. If number($Ret[0]) > number($Varfragini) Then "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook
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