Jump to content

WTF?!? FileReadLine() issue...


Recommended Posts

HI, long time user, first-time poster. I am writing a script to help with an MP3 collection cleanup after I lost my data hard drive (long story, don't buy Maxtor DiamondMax 1TB drive...).

Anyway, I have a text file that I generated at the command line (with console redirection) in Win XP SP3 to list the files in my particular directory using the command:

dir *.mp3 /B>filelist.txt

The file generated successfully, and I've confirmed that it has the correct 0x0D and 0x0A (CRLF) characters at the end of each line. However, when I try to read the file in using the following code I only ever get the first line, over and, over and over...

#include-once
#Include <File.au3>
#Include <ID3.au3>
#Include <extprop.au3>
#Include <array.au3>

Dim $FileData[7] = ["","","","","","",""]
Dim $Debug = 1
Dim $ListFile = ""
Dim $Filename = ""
Dim $ArtistConfidence = 0
Dim $AuthorIsArtist = 0
Dim $AuthorIsV1Artist = 0
Dim $AuthorIsV2Artist = 0
Dim $ArtistIsV1Artist = 0
Dim $ArtistIsV2Artist = 0
Dim $V1ArtistIsV2Artist = 0
Dim $file = ""
Dim $szDrive, $szDir, $szFName, $szExt
Dim $FileDrive = ""
Dim $FileDirectory = ""
Dim $ListFileName = ""
Dim $ListFileExtension = ""
Dim $a = 0
Dim $b = 0




;$ListFile = FileOpenDialog("Select List File", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "Text List File (*.txt)", 1 + 4 )
;$Location = _PathSplit($ListFile, $szDrive, $szDir, $szFName, $szExt )
;$FileDrive = $szDrive
;$FileDirectory = $szDir
;$ListFileName = $szFName
;$ListFileExtension = $szExt


;If $Debug Then
;   MsgBox ( 0, "Data:", $FileDrive & @CRLF & $FileDirectory & @CRLF & $ListFileName & @CRLF & $ListFileExtension )
;EndIf


; Read in lines of text until the EOF is reached
$ListFile = "e:\music_backup\FileListShort.txt"
$b = _FileCountLines( $ListFile )
MsgBox ( 0, "Line Count", $b )

Do
    $line = FileReadLine( $ListFile )
    $EOF = @error
;   $Filename = $FileDrive & $FileDirectory & $line    <--- Commented out to try to find the problem...
    If $Debug Then
        ;MsgBox ( 0, "Debug", $a & @CRLF & "File Name: " & $line & @CRLF & $Filename ) <--- Commented out to try to find the problem...
        MsgBox ( 0, "Debug", $a & @CRLF & "File Name: " & $line )
        Sleep ( 250 )
    EndIf
    $line = ""
    $Filename = ""
    $a = $a + 1

Until $EOF = -1
FileClose($ListFile)

Exit

;There is more code below this line but I have it commented out in the short test script...

So what the heck is going on? I'm using this same exact filereadline code in another script which has been running for several months without problems...

Attached below for your reading pleasure is the text file I'm trying to get file names out of...

Thanks in advance for your help.

-Tim

[Late Edit:] I should note that I attempted using the _FileLineCount function and it replied with the correct line quantity... -T

FileListShort.txt

Edited by tim292stro
Link to comment
Share on other sites

If you want to use FileReadLine without specifying the Line parameter, then you have to open a file handle with FileOpen first.

ie: Instead of this:

$File = 'c:\test.txt'
While 1
    $Line = FileReadLine($File)
    If @error = -1 Then Exit
    MsgBox(0, '', $Line)
WEnd

Use this:

$File = FileOpen('c:\test.txt', 0)
While 1
    $Line = FileReadLine($File)
    If @error = -1 Then Exit
    MsgBox(0, '', $Line)
WEnd
FileClose($File)
Edited by RobSaunders
Link to comment
Share on other sites

If you want to use FileReadLine without specifying the Line parameter, then you have to open a file handle with FileOpen first....

Huh... Somehow I missed that call - I guess in my 11:45PM stuper I thought the "FileOpenDialog" command was doing the same thing as the FileOpen command - consider me schooled... :)

Thanks!

-T

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...