deef99 Posted May 24, 2011 Share Posted May 24, 2011 Got a txt file that looks like this: Date: 05/21/2011,Time: 00:00-00:30,5180401,6,0:00,0:00,0:00,0,0,0,0:00,0,0,0,0,0,0,0,0,0,0,0,0 Date: 05/21/2011,Time: 00:00-00:30,5180403,1,0:00,0:00,0:00,0,0,0,0:00,0,0,0,0,0,0,0,0,0,0,0,0 Date: 05/22/2011,Time: 00:30-01:00,5180401,6,0:00,0:00,0:00,0,0,0,0:00,0,0,0,0,0,0,0,0,0,0,0,0 Date: 05/22/2011,Time: 01:30-02:00,5181401,1,0:00,0:00,0:00,0,0,0,0:00,0,0,0,0,0,0,0,0,0,0,0,0 Date: 05/23/2011,Time: 02:00-02:30,5180501,2,0:00,0:00,0:00,0,0,0,0:00,0,0,0,0,0,0,0,0,0,0,0,0 I have to break the file down into multiple files by date+time. For each date and time "group", I need to out the data starting from the 518xxxx to the end of the line. So the above should produce 4 files. Here is what I have so far. The files are getting created, but they are empty. Not sure where my problem is. Can anyone assist please? Fast approaching my deadline with nothing of use! #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=C:\avaya\VecAnnFile.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Date.au3> #include <File.au3> $file = FileOpen("c:\test\out521.csv", 0) $result = "" $vnum = "" $ann = "" $logfile = "" $vtime = "" $vdate = "" $pt = "" $pd = "" $rr = "" $ss = "" While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop ;grab the date and time of the line $vdate = StringMid($line, 1, 17) $vtime = StringMid($line, 19, 18) ;create a file with random name $ann = Random(10, 10000, 1) $logfile = "c:\test\" & $ann & ".txt" FileOpen($logfile, 1) ;compare dates $rr=StringCompare($vdate,$pd,2) If $rr = 0 Then ;compare times $ss = StringCompare($vtime,$pt,2) If $ss = 0 Then $result = StringMid($line, 38, 70) FileWrite($logfile, $result & @CRLF) $pd = $vdate $pt = $vtime EndIf EndIf FileClose($logfile) WEnd Link to comment Share on other sites More sharing options...
sleepydvdr Posted May 24, 2011 Share Posted May 24, 2011 The first thing I noticed is your line $rr=StringCompare($vdate,$pd,2) compares $vdate, which has a value to $pd, which you initialized to nothing ($pd = ""). #include <ByteMe.au3> Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 24, 2011 Moderators Share Posted May 24, 2011 deef99, I rewrote the whole thing and I think it does what you want now: expandcollapse popup#include <Date.au3> #include <File.au3> Global $result, $hLogFile, $vtime, $vdate, $pt, $pd Global $aLines _FileReadToArray("data.txt", $aLines) For $i = 1 To $aLines[0] $line = $aLines[$i] ;grab the date and time of the line $vdate = StringMid($line, 7, 10) $vtime = StringMid($line, 24, 11) ; If either date or time change If $vdate <> $pd Or $vtime <> $pt Then ConsoleWrite("Opening new file at line " & $i & @CRLF) ; Save current date/time $pd = $vdate $pt = $vtime ; Close Existing file FileClose($hLogFile) ; Create a new file with random name $ann = Random(10, 10000, 1) $hLogFile = @ScriptDir & "\" & $ann & ".txt" FileOpen($hLogFile, 1) EndIf $result = StringMid($line, 36, 72) FileWrite($hLogFile, $result & @CRLF) Next FileClose($hLogFile) Please ask if you have any questions. 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...
deef99 Posted May 24, 2011 Author Share Posted May 24, 2011 Ask a question??? OMG!!!! I am overwhelmed with your ability to write new code so quickly...thank you so much! I ran it...and it is breaking the file at the right places...but I am not getting any files created. I did change @scriptdir to C:\test...did I do that incorrectly? Again, really, can't thank you enough for your generosity! #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=C:\avaya\VecAnnFile.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Date.au3> #include <File.au3> Global $result, $hLogFile, $vtime, $vdate, $pt, $pd Global $aLines _FileReadToArray("c:\test\out521.csv", $aLines) For $i = 1 To $aLines[0] $line = $aLines[$i] ;grab the date and time of the line $vdate = StringMid($line, 7, 10) $vtime = StringMid($line, 24, 11) ; If either date or time change If $vdate <> $pd Or $vtime <> $pt Then ConsoleWrite("Opening new file at line " & $i & @CRLF) ; Save current date/time $pd = $vdate $pt = $vtime ; Close Existing file FileClose($hLogFile) ; Create a new file with random name $ann = Random(10, 10000, 1) $hLogFile = "c:\test" & $ann & ".txt" FileOpen($hLogFile, 1) EndIf $result = StringMid($line, 36, 72) FileWrite($hLogFile, $result & @CRLF) Next FileClose($hLogFile) Link to comment Share on other sites More sharing options...
sahsanu Posted May 24, 2011 Share Posted May 24, 2011 I did change @scriptdir to C:\test...did I do that incorrectly?Yes, you need to use c:\test\ Link to comment Share on other sites More sharing options...
deef99 Posted May 24, 2011 Author Share Posted May 24, 2011 I found it....I didn't add the "\" to the filename...it's working now! Melba23 - You Are the One! thank you thank you thank you! 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