Moderators JLogan3o13 Posted April 7, 2010 Moderators Share Posted April 7, 2010 I have been working on a script to use in conjunction with a command line defragmenting tool. The tool analyzes the drive(s), then spits out a report. I'd like to have the script read the number of fragmented items, and then take some action thereafter. The problem I am having is getting the script to read only what I want out of the log file. I've been playing around with FileRead and FileReadLine, but am not coming up with what I need. See below for an example of the log file by line: 1-12 omiited.... 13. <blank> 14. Unfragmented items: 26,756,861,952 bytes 112,645 items 15. Fragmented items: 6,966,956,032 bytes 2,677 items I would like to read line 14, but only the number of unfragmented bytes (26,756,861,952), and then use ClipPut to use this info late in the script. I would then read the fragmented bytes in line 15, and do the same. Can anyone offer any suggestions, or let me know that this is not feasible? Thanks. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
sb1920alk Posted April 7, 2010 Share Posted April 7, 2010 I have been working on a script to use in conjunction with a command line defragmenting tool. The tool analyzes the drive(s), then spits out a report. I'd like to have the script read the number of fragmented items, and then take some action thereafter. The problem I am having is getting the script to read only what I want out of the log file. I've been playing around with FileRead and FileReadLine, but am not coming up with what I need. See below for an example of the log file by line:1-12 omiited....13. <blank>14. Unfragmented items: 26,756,861,952 bytes 112,645 items15. Fragmented items: 6,966,956,032 bytes 2,677 itemsI would like to read line 14, but only the number of unfragmented bytes (26,756,861,952), and then use ClipPut to use this info late in the script. I would then read the fragmented bytes in line 15, and do the same. Can anyone offer any suggestions, or let me know that this is not feasible? Thanks.If "unfragmented" and "fragmented" only appear once in the log, you can real the whole file to a variable, split it by lines, then loop through the array of lines. In the loop, if the line contains "unfragmented", use text manipulation to pull out the bytes and set a variable equal to it. Use a different variable for "fragmented".Look at fileread, stringsplit, for...in...next, stringinstr Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 7, 2010 Moderators Share Posted April 7, 2010 JLogan3o13, Something along these lines should work: $sFile = @ScriptDir & "\Defrag.log" $aArray = StringSplit(StringTrimLeft(FileReadLine($sFile, 14), 20), " ") $sUnfrag = $aArray[1] $aArray = StringSplit(StringTrimLeft(FileReadLine($sFile, 15), 18), " ") $sFrag = $aArray[1] MsgBox(0, "Bytes", "Unfragmented: " & $sUnfrag & @CRLF & "Fragmented: " & $sFrag) M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted April 7, 2010 Author Moderators Share Posted April 7, 2010 If "unfragmented" and "fragmented" only appear once in the log, you can real the whole file to a variable, split it by lines, then loop through the array of lines. In the loop, if the line contains "unfragmented", use text manipulation to pull out the bytes and set a variable equal to it. Use a different variable for "fragmented".Look at fileread, stringsplit, for...in...next, stringinstrHi, Thanks for the reply. Unfortunately both words occur numerous times in the log file. I may just chalk this one up to more trouble than its worth. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
kaotkbliss Posted April 7, 2010 Share Posted April 7, 2010 Well, you can still keep the code short and sweet by doing the suggested above. Read the file line by line until you reach Fragmented or Unfragmented, call a function to do what you want when it finds that, it will then return to the loop when done and continue till end of file. Just some thoughts to keep your project a possibility 010101000110100001101001011100110010000001101001011100110010000 001101101011110010010000001110011011010010110011100100001 My Android cat and mouse gamehttps://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek We're gonna need another Timmy! Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted April 7, 2010 Author Moderators Share Posted April 7, 2010 Thanks for all of the suggestions, I believe Melba's snippet gave me enough to get what I want. Thanks again. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted April 7, 2010 Author Moderators Share Posted April 7, 2010 With the assistance of M23's code, I was able to play around with this until I got it to do what I wanted. Below is what I ended up with, after reading that you could nest StringTrim functions. $sFile = "C:\Fragmentation.log" $line1 = FileReadLine($sFile, 14) $line2 = FileReadLine($sFile, 15) $value1 = StringTrimLeft (StringTrimRight($line1, 30), 20) ClipPut( $value1 ) $value2 = StringTrimLeft (StringTrimRight($line2, 30), 24) ClipPut($value2) $frag = $value2 / $value1 * 100 $frag1 = StringTrimRight($frag, 12) $defrag = MsgBox(4, "Fragmentation Level", $frag1 & "%. Would you like to defragment?") Thanks again for the suggestions, works great now. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
sb1920alk Posted April 7, 2010 Share Posted April 7, 2010 With the assistance of M23's code, I was able to play around with this until I got it to do what I wanted. Below is what I ended up with, after reading that you could nest StringTrim functions. $sFile = "C:\Fragmentation.log" $line1 = FileReadLine($sFile, 14) $line2 = FileReadLine($sFile, 15) $value1 = StringTrimLeft (StringTrimRight($line1, 30), 20) ClipPut( $value1 ) $value2 = StringTrimLeft (StringTrimRight($line2, 30), 24) ClipPut($value2) $frag = $value2 / $value1 * 100 $frag1 = StringTrimRight($frag, 12) $defrag = MsgBox(4, "Fragmentation Level", $frag1 & "%. Would you like to defragment?") Thanks again for the suggestions, works great now. ...just to make sure you know it's an option. defrag c: -a -v 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