Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Problem with FileWriteLine

$
0
0
I did a search for this topic and couldn't find an answer. I am seeing an issue with the following function.
[ autoit ]         
Func _GenerateCueSheet()     Local $nSearch=-1, $nTrack=1, $i     Local $sFile, $sToWrite     Local $hFile     Local $arFile, $arTemp, $arTemp2     $nSearch = FileFindFirstFile($sAudibleDirectory & "\*.aa")     ShellExecute("cmd.exe")     Do         Sleep(100)     Until WinExists("cmd")     $hMain=WinGetHandle("cmd")     While 1         FileDelete($sAudibleDirectory&'\temp.txt')         $sFile=FileFindNextFile($nSearch)         If @error Then ExitLoop         WinActivate($hMain)         Send(@ScriptDir&'\AudibleChapters.exe "'&$sAudibleDirectory&'\'&$sFile&'" > "'&$sAudibleDirectory&'\temp.txt"')         Send("{ENTER}")         Do             Sleep(100)         Until FileExists($sAudibleDirectory&'\temp.txt')         $hFile=FileOpen($sAudibleDirectory&'\'&StringReplace($sFile,'.aa','.cue'),2)         FileWriteLine($hFile,'FILE "'&StringReplace($sFile,'.aa','')&'.MP3" MP3')         _FileReadToArray($sAudibleDirectory&'\temp.txt',$arFile)         For $i=0 To Ubound($arFile)-1             If StringRegExp($arFile[$i],'\d\d:\d\d:\d\d:\d\d\d') Then                 $arTemp=StringSplit($arFile[$i],":")                 If StringInStr($arTemp[1],"Total") Then ExitLoop                 If $nTrack<10 Then                     FileWriteLine($hFile,"TRACK 0"&$nTrack&" AUDIO")                 Else                     FileWriteLine($hFile,"TRACK "&$nTrack&" AUDIO")                 EndIf                 $nTrack+=1                 FileWriteLine($hFile,'TITLE "'&$arTemp[1]&'"')                 $arTemp=StringRegExp($arFile[$i],'\d\d:\d\d:\d\d:\d\d\d',1) ;$arTemp[0] has the index                 $arTemp2=StringSplit($arTemp[0],':')                 If $nTrack=2 Then                     FileWriteLine($hFile,"INDEX 01 "&$arTemp2[1]*60+$arTemp2[2]&':'&$arTemp2[3]&':00')                 Else                     FileWriteLine($hFile,"INDEX 01 "&$arTemp2[1]*60+$arTemp2[2]&':'&$arTemp2[3]-1&':00') ;subtract 1 second for offset                 EndIf             EndIf         Next         FileClose($hFile)     WEnd     WinActivate($hMain)     Send("exit{ENTER}") EndFunc

The function uses another program to create a text file containing chapter locations in an audible file. The function parses the data to create a .cue file. The temporary text file is deleted before the command line is run and then the script pauses until the program creates the file. The file is successfully read to an array, but when FileWriteLine is used, only the first line in the cue is written. I can't figure out why the other lines in the file are not written to the file.  If I change the format to create a string and use "FileWrite" everything works as it should:
[ autoit ]         
Func _GenerateCueSheet()     Local $nSearch=-1, $nTrack=1, $i     Local $sFile, $sToWrite     Local $hFile     Local $arFile, $arTemp, $arTemp2     $nSearch = FileFindFirstFile($sAudibleDirectory & "\*.aa")     ShellExecute("cmd.exe")     Do         Sleep(100)     Until WinExists("cmd")     $hMain=WinGetHandle("cmd")     While 1         FileDelete($sAudibleDirectory&'\temp.txt')         $sFile=FileFindNextFile($nSearch)         If @error Then ExitLoop         WinActivate($hMain)         Send(@ScriptDir&'\AudibleChapters.exe "'&$sAudibleDirectory&'\'&$sFile&'" > "'&$sAudibleDirectory&'\temp.txt"')         Send("{ENTER}")         Do             Sleep(100)         Until FileExists($sAudibleDirectory&'\temp.txt')         ;$hFile=FileOpen($sAudibleDirectory&'\'&StringReplace($sFile,'.aa','.cue'),2)         ;FileWriteLine($hFile,'FILE "'&StringReplace($sFile,'.aa','')&'.MP3" MP3') $sToWrite='FILE "'&StringReplace($sFile,'.aa','')&'.MP3" MP3'         _FileReadToArray($sAudibleDirectory&'\temp.txt',$arFile)         For $i=0 To Ubound($arFile)-1             If StringRegExp($arFile[$i],'\d\d:\d\d:\d\d:\d\d\d') Then                 $arTemp=StringSplit($arFile[$i],":")                 If StringInStr($arTemp[1],"Total") Then ExitLoop                 If $nTrack<10 Then                     ;FileWriteLine($hFile,"TRACK 0"&$nTrack&" AUDIO") $sToWrite&=@CRLF&"TRACK 0"&$nTrack&" AUDIO"                 Else                     ;FileWriteLine($hFile,"TRACK "&$nTrack&" AUDIO") $sToWrite&=@CRLF&"TRACK "&$nTrack&" AUDIO"                 EndIf                 $nTrack+=1                 ;FileWriteLine($hFile,'TITLE "'&$arTemp[1]&'"') $sToWrite&=@CRLF&'TITLE "'&$arTemp[1]&'"'                 $arTemp=StringRegExp($arFile[$i],'\d\d:\d\d:\d\d:\d\d\d',1) ;$arTemp[0] has the index                 $arTemp2=StringSplit($arTemp[0],':')                 If $nTrack=2 Then                     ;FileWriteLine($hFile,"INDEX 01 "&$arTemp2[1]*60+$arTemp2[2]&':'&$arTemp2[3]&':00') $sToWrite&=@CRLF&"INDEX 01 "&$arTemp2[1]*60+$arTemp2[2]&':'&$arTemp2[3]&':00'                 Else                     ;FileWriteLine($hFile,"INDEX 01 "&$arTemp2[1]*60+$arTemp2[2]&':'&$arTemp2[3]-1&':00') ;subtract 1 second for offset $sToWrite&=@CRLF&"INDEX 01 "&$arTemp2[1]*60+$arTemp2[2]&':'&$arTemp2[3]-1&':00'                 EndIf             EndIf         Next $hFile=FileOpen($sAudibleDirectory&'\'&StringReplace($sFile,'.aa','.cue'),2) FileWrite($hFile,$sToWrite)         FileClose($hFile)     WEnd     WinActivate($hMain)     Send("exit{ENTER}") EndFunc

While the FileWrite does work, I am curious why the FileWriteLine doesn't. I have attached a sample output text file that is generated by the command line program.

Attached Files

  • Attached File  temp.txt   660bytes   3 downloads

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>