Jump to content
aa2zz6

_FileListToArray Directory Issue

Recommended Posts

aa2zz6
Posted (edited)

 

I am trying to look in a directory with text files stored with materials and find out how many have the searched gas component defined as $searchWord. 

When I use this the file has to be inside the folder with the documents but once I move it outside the script it give me an error

$aFileList = _FileListToArray(@ScriptDir, "*.txt")

Error

error: syntax error
    $aFileList = _FileListToArray(@ScriptDir, &
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

 

#include <File.au3>
#include <Array.au3>
Global $searchWord = "Inline Valves" ; Find Dimp Item
Global $read ; Reads each txt file

Readtxt()

Func Readtxt()
    $aFileList = _FileListToArray(@ScriptDir & "\Documents\" & "*.txt")
    If @error = 1 Then
        MsgBox(0, "", "No Files\Folders Found.")
        Exit
    EndIf

    Local $aFileStrings[$aFileList[0] + 1][2] = [[$aFileList[0]]]

    For $i = 1 To $aFileList[0]
        ; Add file name to [n][0] element
        $aFileStrings[$i][0] = $aFileList[$i]
        ; Read file content
        $sFile = FileRead(@ScriptDir & "\" & $aFileList[$i])
        ; Add file content to [n][1] element
        $aFileStrings[$i][1] = $sFile
        ConsoleWrite($aFileStrings[$i][1])
        $read = FileRead($aFileList[$i])
        If StringRegExp($read, $searchWord) Then
            MsgBox(0, "Dimp Item", "Match")
            ExitLoop
        Else
            ;MsgBox(0, "Dimp Item", "No match") ; Certain documents will not have the same installed components
        EndIf
    Next
    _ArrayDisplay($aFileStrings)
EndFunc   ;==>Readtxt

Adding the directory will enable the @error

If @error = 1 Then
    MsgBox(0, "", "No Files\Folders Found.")
    Exit
EndIf

 

 

Edited by aa2zz6

Share this post


Link to post
Share on other sites
Subz
Posted (edited)

Why do you have an ampersand in your code above?

The first parameter should be a folder, the second parameter the filter.

$aFileList = _FileListToArray(@ScriptDir & "\Documents\" & "*.txt")

It should be

$aFileList = _FileListToArray(@ScriptDir & "\Documents\", "*.txt")

Edited by Subz
  • Thanks 1

Share this post


Link to post
Share on other sites
aa2zz6

Thank you. I didn't realize this.

Share this post


Link to post
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

×