Jump to content

cicle : read some line in files


Recommended Posts

hello to all,

i need to read some lines in 190 files.

post some code that have error but can't find where:

; Shows the filenames of all files in the current directory.
$search = FileFindFirstFile("C:\temp\*.txt)  

; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf



While 1
    $file = FileFindNextFile($search) 
    If @error Then ExitLoop
    
    

    $file_read = FileOpen($file, 0)
    $line_01 = FileReadLine($file, 1)

    msgbox(0, "This is sfirst line of : " & $file, $line_01)    

    FileClose($file)


WEnd

; Close the search handle
FileClose($search)

in this example sscript should read first line for every file, but doesn't.

anyone can correct me please ?

thank you,

m.

Link to comment
Share on other sites

Try this

; Shows the filenames of all files in the current directory.
$search = FileFindFirstFile("C:\temp\*.txt" )

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop
    ConsoleWrite ( "$file : " & $file & @Crlf )
    $line_01 = FileReadLine ( 'c:\' & $file, 1 )
    ConsoleWrite ( "$line_01 : " & $line_01 & @Crlf )
    msgbox ( 0, '', "This is sfirst line of : " & $file & @crlf & $line_01 )
    FileClose($file)
WEnd

; Close the search handle
FileClose($search)

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

Hi myspacee,

if you need to read more than 1 line per file, I suggest to use _FileReadToArray instead of FileReadLine() because it's faster.

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
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...