jslegers Posted September 2, 2008 Posted September 2, 2008 Hi, I have made a script which starts JkDefrag with a few parameters and which tests if files are fragmented. Here is the script : expandcollapse popupRegion;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=Defrag.ico #AutoIt3Wrapper_outfile=Defrag.exe #AutoIt3Wrapper_Res_Description=Defrag script for JKDefrag #AutoIt3Wrapper_Res_Fileversion=1.3.2.0 #EndRegion;**** Directives created by AutoIt3Wrapper_GUI **** #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 This is an example of the log file which is being created : 13:36:47 JkDefrag v3.36 13:36:47 Date: 2008/09/02 13:36:47 Windows version: v5.1 build 2600 Service Pack 3 13:36:47 Commandline argument '-a' accepted, optimizemode = 1 13:36:47 Commandline argument '-l' accepted, logfile = C:\Analyze_C.log 13:36:47 NtfsDisableLastAccessUpdate is active, ignoring LastAccessTime for SpaceHogs. 13:36:47 Processing 'c:' 13:36:47 Opening volume '\\?\Volume{e8f1f9b1-60cc-11dd-b040-806d6172696f}' at mountpoint 'c:' 13:36:47 Input mask: c:\* 13:36:47 Phase 1: Analyze 13:36:47 This is an NTFS disk. 13:36:49 Finished. 13:36:49 - Total disk space: 34356477952 bytes (31.9970 gigabytes), 8387812 clusters 13:36:49 - Bytes per cluster: 4096 bytes 13:36:49 - Number of files: 27813 13:36:49 - Number of directories: 3223 13:36:49 - Total size of analyzed items: 12835758080 bytes (11.9542 gigabytes), 3133730 clusters 13:36:49 - Number of fragmented items: 272 (0.8764% of all items) 13:36:49 - Total size of fragmented items: 379191296 bytes, 92576 clusters, 2.9542% of all items, 1.1037% of disk 13:36:49 - Free disk space: 17254735872 bytes, 4212582 clusters, 50.2227% of disk 13:36:49 - Number of gaps: 627 13:36:49 - Number of small gaps: 367 (58.5327% of all gaps) 13:36:49 - Size of small gaps: 6938624 bytes, 1694 clusters, 0.0402% of free disk space 13:36:49 - Number of big gaps: 260 (41.4673% of all gaps) 13:36:49 - Size of big gaps: 17247797248 bytes, 4210888 clusters, 99.9598% of free disk space 13:36:49 - Average gap size: 6718.6316 clusters 13:36:49 - Biggest gap: 13322166272 bytes, 3252482 clusters, 77.2088% of free disk space 13:36:49 - Average end-begin distance: 611006 clusters, 7.2844% of volume size I'm doing a check on line number 18 : 13:36:49 - Number of fragmented items: 272 (0.8764% of all items) If this number is higher than FragmentedFiles in the ini it will start Defragmentation. The problem is I'm getting the next error : R:\Defrag.au3 (68) : ==> Subscript used with non-Array variable.: ConsoleWrite ( $Ret[0] & @LF ) ConsoleWrite ( $Ret^ ERROR What could be the problem. I'm using the latest version of autoit. Here is the ini file which is used by the script : [General] FragmentedFiles=100 Timeout=1 TrayIcon=1 Optimize=1
BrettF Posted September 2, 2008 Posted September 2, 2008 Are you sure you are getting data from the log? I'd test what is being returned by each function in that particular for loop. Cheers, Brett Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
jslegers Posted September 2, 2008 Author Posted September 2, 2008 Are you sure you are getting data from the log? I'd test what is being returned by each function in that particular for loop. Cheers, BrettHi Brett, The strange thing is it has always worked. I creates the file nicely. Looks like this part : $Log = FileReadLine ( "C:\Analyze_" & StringTrimRight ( $Vardrive[$i], 1 ) & ".log" ,18 ) $Ret = StringRegExp ( $Log, ": ([0-9]{0,}),", 1, 1 ) doesn't work anymore.
zfisherdrums Posted September 2, 2008 Posted September 2, 2008 (edited) Hi Brett, The strange thing is it has always worked. I creates the file nicely. Looks like this part : $Log = FileReadLine ( "C:\Analyze_" & StringTrimRight ( $Vardrive[$i], 1 ) & ".log" ,18 ) $Ret = StringRegExp ( $Log, ": ([0-9]{0,}),", 1, 1 ) doesn't work anymore. Using the log file provided, the regex return "272" when I remove the trailing comma from the expression. $Log = FileReadLine ( "log.log" ,18 ) $Ret = StringRegExp ( $Log, ": ([0-9]{0,})", 1, 1 ) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Ret = ' & $Ret & @crlf & '>Error code: ' & @error & @crlf);### Debug Console ConsoleWrite($Ret[0] & @CRLF) Output: >"C:\Program Files\AutoIt3\SciTe\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Documents and Settings\Fisherz\Desktop\test.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams +>08:24:55 Starting AutoIt3Wrapper v.1.10.1.7 Environment(Language:0409 Keyboard:00000409 OS:WIN_XP/Service Pack 2 CPU:X86) >Running AU3Check (1.54.13.0) from:C:\Program Files\AutoIt3 +>08:24:55 AU3Check ended.rc:0 >Running:(3.2.12.1):C:\Program Files\AutoIt3\autoit3.exe "C:\Documents and Settings\Fisherz\Desktop\test.au3" @@ Debug(12) : $Ret = >Error code: 0 272 +>08:24:56 AutoIT3.exe ended.rc:0 >Exit code: 0 Time: 1.370 Is that what you're expecting? Edited September 2, 2008 by zfisherdrums Identify .NET controls by their design time namesLazyReader© could have read all this for you. Unit Testing for AutoItFolder WatcherWord Doc ComparisonThis here blog...
jslegers Posted September 2, 2008 Author Posted September 2, 2008 Using the log file provided, the regex return "272" when I remove the trailing comma from the expression. $Log = FileReadLine ( "log.log" ,18 ) $Ret = StringRegExp ( $Log, ": ([0-9]{0,})", 1, 1 ) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Ret = ' & $Ret & @crlf & '>Error code: ' & @error & @crlf);### Debug Console ConsoleWrite($Ret[0] & @CRLF) Output: >"C:\Program Files\AutoIt3\SciTe\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Documents and Settings\Fisherz\Desktop\test.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams +>08:24:55 Starting AutoIt3Wrapper v.1.10.1.7 Environment(Language:0409 Keyboard:00000409 OS:WIN_XP/Service Pack 2 CPU:X86) >Running AU3Check (1.54.13.0) from:C:\Program Files\AutoIt3 +>08:24:55 AU3Check ended.rc:0 >Running:(3.2.12.1):C:\Program Files\AutoIt3\autoit3.exe "C:\Documents and Settings\Fisherz\Desktop\test.au3" @@ Debug(12) : $Ret = >Error code: 0 272 +>08:24:56 AutoIT3.exe ended.rc:0 >Exit code: 0 Time: 1.370 Is that what you're expecting?Hi, Thanks. The trailing comma was the problem.
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