dragonlord Posted August 2, 2006 Share Posted August 2, 2006 i need some help parsing a plain text file with the following structure..... '---------------------------------------------------------------------------- ' File: C:\Documents and Settings\adcfbc0\Desktop\Review-FX\Review-FX\Pending_Foreign_Exchange_Contracts_by_Currency.bas ' ' Generated From: C:\Documents and Settings\adcfbc0\Desktop\Review-FX\Review-FX\Pending_Foreign_Exchange_Contracts_by_Currency.rod ' Generated On: 07/31/06 02:34:08 '---------------------------------------------------------------------------- ' ' Modules generated into this Basic file include: ' Module C:\Workshop\libX\IMBase.rol ' ' Module C:\Workshop\libX\Workbooks.rol ' ' Module C:\Workshop\libX\IMExpress.rod ' Includes C:/Workshop/libX/Workbooks.rol ' Includes C:/Workshop/libX/IMBase.rol ' ' Module C:\Workshop\libX\acctSSS.rol ' ' Module C:\Workshop\libX\getAsss.rol ' ' Module C:\Workshop\libX\RelativeDate.rol ' ' Module C:\Documents and Settings\adcfbc0\Desktop\Review-FX\Review-FX\Pending_Foreign_Exchange_Contracts_by_Currency.rod ' Includes C:\Workshop\libX\IMBase.rol ' Includes C:/Workshop/libX/IMExpress.rod ' Includes C:/Workshop/libX/acctSSS.rol ' Includes C:/Workshop/libX/getAsss.rol ' Includes C:/Workshop/libX/RelativeDate.rol ' '---------------------------------------------------------------------------- ' '---------------------------------------- ' Global type and variable declarations '---------------------------------------- Declare Option Internal '----------------------- rest of the file............................ This is the requirement, after the line ' Modules generated into this Basic file include:' until ''----------------------------------------------------------------------------' i need to check for all references of c:/filename .It can be either 'Module c:\filename' or either 'includes C:/filename' Any ideas ???? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 2, 2006 Moderators Share Posted August 2, 2006 Where's the code you've attempted? 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...
dragonlord Posted August 2, 2006 Author Share Posted August 2, 2006 not yet started with the code. :-) . i'm actually a newbie with autoit. Link to comment Share on other sites More sharing options...
/dev/null Posted August 2, 2006 Share Posted August 2, 2006 (edited) not yet started with the code. :-) .i'm actually a newbie with autoit.to get you started, read the help file sections of:_FileReadToArray()While...WEndStringInStr()StringReplace()_FileWriteFromArraySee also this example. It's not doing what you want, but it shows you how to use the things I mentioned above.CheersKurt Edited August 2, 2006 by /dev/null __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
dragonlord Posted August 2, 2006 Author Share Posted August 2, 2006 I'm having problems reading the file into the array. the same file mentioned in my previous post, when read to array and printed shows junk values. what am i doing wrong here ? ..... #include <GUIConstants.au3> #include <Process.au3> #include <file.au3> #include <Array.au3> $ParentWin = GUICreate("Bas-Cheq!", 250,130) GUISetState(@SW_SHOW) $selectfileBut = GUICtrlCreateButton("Select .Bas File",65,3, 100) While 1 $msg = GUIGetMsg(1) Select Case $msg[0] = $GUI_EVENT_CLOSE GUIDelete() Exit Case $msg[0] = $selectfileBut $basfile = FileOpenDialog("Select .bas file to be checked", "C:\Windows\", "Actuate Basic Files (*.bas)", 1) If $basfile = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf GUICtrlCreateInput ($basfile , 10, 35, 300, 20) $match_pattern1 = "Module C:" $match_pattern2 = "Includes C:" Dim $lines _FileReadToArray($basfile,$lines) _ArrayDisplay ( $lines, "gbc" ) ;For $i = 1 To 10 ; If StringInStr($lines[$i],$match_pattern1) or StringInStr($lines[$i],$match_pattern2)Then ; MsgBox(0, "Found", $lines[$i]) ; EndIf ;Next EndSelect WEnd Link to comment Share on other sites More sharing options...
/dev/null Posted August 2, 2006 Share Posted August 2, 2006 (edited) I'm having problems reading the file into the array. the same file mentioned in my previous post, when read to array and printed shows junk values. what am i doing wrong here ? .....What junk value are you talking about? It looks O.K. for me.CheersKurt Edited June 19, 2007 by /dev/null __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
dragonlord Posted August 2, 2006 Author Share Posted August 2, 2006 i tried this : While 1 $line = FileReadLine($basfile) If @error = -1 Then ExitLoop MsgBox(0, "Line read:", $line) Wend but even this shows junk values.... somebody help......... Link to comment Share on other sites More sharing options...
dragonlord Posted August 2, 2006 Author Share Posted August 2, 2006 it's printing funny ascii characters. i'm attaching the code and the sample .bas fileBAS_Cheq.au3 Link to comment Share on other sites More sharing options...
/dev/null Posted August 2, 2006 Share Posted August 2, 2006 it's printing funny ascii characters. i'm attaching the code and the sample .bas fileit's printing funny ascii characters. i'm attaching the code and the sample .bas fileMost certainly your *.bas file was written with a UNICODE character set. Did you edit and save the file with notepad or any other editor that writes UNICODE files?BTW you attached the AU3 file and not the .bas file!CheersKurt __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
dragonlord Posted August 2, 2006 Author Share Posted August 2, 2006 (edited) WOW. Nice catch. I had used notepad for editing the bas file and it got saved in unicode.Saved in ansi and it works. but another prob now. Since the file size is huge (5-8 mb bas file), it takes long time to read into the array. Any way to read only the first n lines of the file into array. N will be the line having the third occurance of " '- ". Edited August 2, 2006 by dragonlord Link to comment Share on other sites More sharing options...
/dev/null Posted August 2, 2006 Share Posted August 2, 2006 (edited) WOW. Nice catch. I had used notepad for editing the bas file and it got saved in unicode.Saved in ansi and it works. but another prob now. Since the file size is huge (5-8 mb bas file), it takes long time to read into the array. Any way to read only the first n lines of the file into array. N will be the line having the third occurance of " '- ". O.K. 8 MB is too large for _FileReadToArray(). You should open the File and read every line with FileReadLine(), then check whatever you want to check and then close the file. StringSplit() will help also. Help file sample: $file = FileOpen("test.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop MsgBox(0, "Line read:", $line); <== replace this with your check code! Wend FileClose($file) Cheers Kurt Edited August 2, 2006 by /dev/null __________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf * Link to comment Share on other sites More sharing options...
bluebearr Posted August 2, 2006 Share Posted August 2, 2006 (edited) Here's an idea: $basfileH = FileOpen($basfile, 0) Dim $lines[1], $idx = 0, $i = 0 While $idx < 3 if $i > 0 Then ReDim $lines[$i + 1] EndIf $lines[$i] = FileReadLine($basfileH) If @error = -1 Then ExitLoop If StringLeft($lines[$i], 2) = "'-" Then $idx = $idx + 1 $i = $i + 1 Wend FileClose($basfileH) _ArrayDisplay ( $lines, "gbc" ) You need $basfileH because otherwise FileReadLine just keeps reading the first line of the file. Edited August 2, 2006 by bluebearr BlueBearrOddly enough, this is what I do for fun. 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