SilviuGirnita Posted January 25, 2008 Share Posted January 25, 2008 Hi all My following little script reads a text file (Administrator_audfiles.txt) and extract the information corresponding to the lines which contain the data about some recordings (start time, phone number and channel). However, it has a strange behaviour: for the first two lines it works perfectly but beginning with the third, all the next lines are no more processed. And if I replace FileMove with FileCopy in the last lines, the situation is the same. Here is the code: #include <file.au3> $Nr_linii_t = _FileCountLines("C:\NICE\wav\Administrator_audfiles.txt") MsgBox(0, "Nr lines in text files is:", $Nr_linii_t) $Nr_linii=Int($Nr_linii_t/5 ) MsgBox(0, "Nr lines 5 by 5:", $Nr_linii) $a=1 While $a <= $Nr_linii $b=$a*5 MsgBox(0, "Step nr:", $a) MsgBox(0, "Line nr:", $ $file = FileOpen("C:\NICE\wav\Administrator_audfiles.txt", 0) Sleep(1000) $line = FileReadLine($file,$ $result = StringLeft($line, 35) $result1=StringStripWS($result, 8) MsgBox(0, "File to rename:", $result1) $text = StringReplace($line,":", "-") ;replace in line 5 chars ':' and '/' with '-' $text1 = StringReplace($text,"/", "-") $text2 = StringStripWS($text1, 8) MsgBox(0, "The new string is:", $text2) $x=31 $an=@YEAR $var = StringMid($text2, $x, 4) MsgBox(0, "4 chars extracted beginning with the 31st position are:", $var) while $an<>$var $x=$x+1 $var = StringMid($text2, $x, 4) WEnd MsgBox(0, "This year:", $var) ;this year $y=$x-6 $var_y = StringMid($text2, $y, 10) MsgBox(0, "Current date:", $var_y) $data=StringReplace($var_y,"+", " ") MsgBox(0, "Current date without plus sign:", $data) ;current hour $w=$x+4 $var_w=StringMid($text2, $w, 8) $ora1=StringReplace($var_w,"A", " ") $ora2=StringReplace($ora1,"P", " ") $ora=StringStripWS($ora2, 8) MsgBox(0, "Current hour:", $ora) ;Current channel $char_dr = StringRight($text2, 10) MsgBox(0, "The last 10 chars are:", $char_dr) $logger=StringMid($char_dr, 1, 7) ;MsgBox(0, "Final logger is:", $logger) If $logger=4719604 Then $can=StringRight($char_dr, 3) ElseIf $logger<>4719604 Then $can=StringRight($char_dr, 2) EndIf $canal=StringTrimRight($can, 1) If $canal=1 Then $tel=200 ElseIf $canal=2 Then $tel=201 ElseIf $canal=3 Then $tel=202 ElseIf $canal=4 Then $tel=203 ElseIf $canal=5 Then $tel=204 ElseIf $canal=6 Then $tel=205 ElseIf $canal=7 Then $tel=206 ElseIf $canal=8 Then $tel=207 ElseIf $canal=9 Then $tel=208 ElseIf $canal=10 Then $tel=209 ElseIf $canal=11 Then $tel=210 ElseIf $canal=12 Then $tel=211 ElseIf $canal=13 Then $tel=212 ElseIf $canal=14 Then $tel=213 ElseIf $canal=15 Then $tel=214 ElseIf $canal=16 Then $tel=215 EndIf MsgBox(0, "The phone is:", $tel) MsgBox(0, "The file have to be renamed:", $data & $ora & $tel) FileMove($result1 & ".wav", "C:\NICE\wav\" & $data & "_" & $ora &"_" & $tel & "_" & $canal & "_DJ.wav") Sleep(1000) FileClose($file) $a=$a+1 WEnd MsgBox(0, "All is:", "OK") Exit The content of the file C:\NICE\wav\Administrator_audfiles.txt is: 1/22/2008 10:52:16 AM SUPERVISOR, NICE [File Name] [AUD] [WAV] [Talking Clock] [start Time] [stop Time] [session ID] [Extension] [Phone Number] [Logger] [Channel] C:\NICE\wav\Administrator_WAV_123 + 1/22/2008 10:51:23 AM1/22/2008 10:51:35 AM 22213 4719604 8 1 1/22/2008 10:52:26 AM SUPERVISOR, NICE [File Name] [AUD] [WAV] [Talking Clock] [start Time] [stop Time] [session ID] [Extension] [Phone Number] [Logger] [Channel] C:\NICE\wav\Administrator_WAV_124 + 1/22/2008 10:51:29 AM1/22/2008 10:51:35 AM 22334 4719604 4 1 and so on. The directory C:\NICE\wav\ contains the .wav files with the names like this: Administrator_WAV_123.wav Administrator_WAV_124.wav and so on Please take a look on this code. Maybe some of you may observe where is the critical point. I have no more idea! It's really strange because the first two lines are normally processed and the variables for the next lines are returned with normal values in message boxes. Thanks in advance! sylroReplaceString.au3 Link to comment Share on other sites More sharing options...
martin Posted January 25, 2008 Share Posted January 25, 2008 (edited) Hi all My following little script reads a text file (Administrator_audfiles.txt) and extract the information corresponding to the lines which contain the data about some recordings (start time, phone number and channel). However, it has a strange behaviour: for the first two lines it works perfectly but beginning with the third, all the next lines are no more processed. And if I replace FileMove with FileCopy in the last lines, the situation is the same. Here is the code: #include <file.au3> $Nr_linii_t = _FileCountLines("C:\NICE\wav\Administrator_audfiles.txt") MsgBox(0, "Nr lines in text files is:", $Nr_linii_t) $Nr_linii=Int($Nr_linii_t/5 ) MsgBox(0, "Nr lines 5 by 5:", $Nr_linii) $a=1 While $a <= $Nr_linii $b=$a*5 MsgBox(0, "Step nr:", $a) MsgBox(0, "Line nr:", $ $file = FileOpen("C:\NICE\wav\Administrator_audfiles.txt", 0) Sleep(1000) $line = FileReadLine($file,$ $result = StringLeft($line, 35) $result1=StringStripWS($result, 8) MsgBox(0, "File to rename:", $result1) $text = StringReplace($line,":", "-") ;replace in line 5 chars ':' and '/' with '-' $text1 = StringReplace($text,"/", "-") $text2 = StringStripWS($text1, 8) MsgBox(0, "The new string is:", $text2) $x=31 $an=@YEAR $var = StringMid($text2, $x, 4) MsgBox(0, "4 chars extracted beginning with the 31st position are:", $var) while $an<>$var $x=$x+1 $var = StringMid($text2, $x, 4) WEnd MsgBox(0, "This year:", $var) ;this year $y=$x-6 $var_y = StringMid($text2, $y, 10) MsgBox(0, "Current date:", $var_y) $data=StringReplace($var_y,"+", " ") MsgBox(0, "Current date without plus sign:", $data) ;current hour $w=$x+4 $var_w=StringMid($text2, $w, 8) $ora1=StringReplace($var_w,"A", " ") $ora2=StringReplace($ora1,"P", " ") $ora=StringStripWS($ora2, 8) MsgBox(0, "Current hour:", $ora) ;Current channel $char_dr = StringRight($text2, 10) MsgBox(0, "The last 10 chars are:", $char_dr) $logger=StringMid($char_dr, 1, 7) ;MsgBox(0, "Final logger is:", $logger) If $logger=4719604 Then $can=StringRight($char_dr, 3) ElseIf $logger<>4719604 Then $can=StringRight($char_dr, 2) EndIf $canal=StringTrimRight($can, 1) If $canal=1 Then $tel=200 ElseIf $canal=2 Then $tel=201 ElseIf $canal=3 Then $tel=202 ElseIf $canal=4 Then $tel=203 ElseIf $canal=5 Then $tel=204 ElseIf $canal=6 Then $tel=205 ElseIf $canal=7 Then $tel=206 ElseIf $canal=8 Then $tel=207 ElseIf $canal=9 Then $tel=208 ElseIf $canal=10 Then $tel=209 ElseIf $canal=11 Then $tel=210 ElseIf $canal=12 Then $tel=211 ElseIf $canal=13 Then $tel=212 ElseIf $canal=14 Then $tel=213 ElseIf $canal=15 Then $tel=214 ElseIf $canal=16 Then $tel=215 EndIf MsgBox(0, "The phone is:", $tel) MsgBox(0, "The file have to be renamed:", $data & $ora & $tel) FileMove($result1 & ".wav", "C:\NICE\wav\" & $data & "_" & $ora &"_" & $tel & "_" & $canal & "_DJ.wav") Sleep(1000) FileClose($file) $a=$a+1 WEnd MsgBox(0, "All is:", "OK") Exit The content of the file C:\NICE\wav\Administrator_audfiles.txt is: 1/22/2008 10:52:16 AM SUPERVISOR, NICE [File Name] [AUD] [WAV] [Talking Clock] [start Time] [stop Time] [session ID] [Extension] [Phone Number] [Logger] [Channel] C:\NICE\wav\Administrator_WAV_123 + 1/22/2008 10:51:23 AM1/22/2008 10:51:35 AM 22213 4719604 8 1 1/22/2008 10:52:26 AM SUPERVISOR, NICE [File Name] [AUD] [WAV] [Talking Clock] [start Time] [stop Time] [session ID] [Extension] [Phone Number] [Logger] [Channel] C:\NICE\wav\Administrator_WAV_124 + 1/22/2008 10:51:29 AM1/22/2008 10:51:35 AM 22334 4719604 4 1 and so on. The directory C:\NICE\wav\ contains the .wav files with the names like this: Administrator_WAV_123.wav Administrator_WAV_124.wav and so on Please take a look on this code. Maybe some of you may observe where is the critical point. I have no more idea! It's really strange because the first two lines are normally processed and the variables for the next lines are returned with normal values in message boxes. Thanks in advance! sylro I think should put your FileOpen and FileClose outside of the While/wend loop rather than keep opening and closing it. You could also saves some lines If $canal > 0 and $canal < 17 Then $tel = 200 +$canal -1 Unfortunately, I don't get a problem with your script using the text file sample. Welcome to the forums Edited January 25, 2008 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
SilviuGirnita Posted January 26, 2008 Author Share Posted January 26, 2008 Thanks for your time, Martin Anywhere I put FileOpen and FileClose, inside or outside the loop, the result was the same. And the same was if I change 'while' loop with a "for - next" cycle. You said: Unfortunately, I don't get a problem with your script using the text file sample. Did you mean all the lines were processed OK in your case? (not just first two lines?) Thanks again for your response! sylro Link to comment Share on other sites More sharing options...
SilviuGirnita Posted February 13, 2008 Author Share Posted February 13, 2008 Sorry, in fact the script works very well. Only my text file had all lines the same, beginning with the third line. That's why the script was renaming only the first two lines. Cheers! sylro 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