Jump to content
Sign in to follow this  
ajit

Help me with _FileListToArray

Recommended Posts

ajit

Hi

I have taken this script almost straight from the Help File. It gives me a list of files with the extensions *.au3 on a txt file but it gives me only the file names and not the path.

I want the full path to appear in the text file. Is is possible?

Please help.

Thanks

Ajit

test.au3

Share this post


Link to post
Share on other sites
ajit

Posting the code:

#include<File.au3>

$avCommon = _FileListToArray(@DesktopDir, "*.au3")

$avUser = _FileListToArray(@DesktopDir, "*.au3")

$sFile = @ScriptDir & "\test.txt"

FileDelete($sFile)

; Write first array to file by string file name

_FileWriteFromArray($sFile, $avCommon, 1)

; Open file and append second array

$hFile = FileOpen($sFile, 1) ; 1 = append

_FileWriteFromArray($hFile, $avUser, 1)

FileClose($hFile)

; Display results

Run("notepad.exe " & $sFile)

Tnx

Share this post


Link to post
Share on other sites
Valuater

Maybe...

#include<File.au3>

$avCommon = _FileListToArray(@ScriptDir, "*.au3")
$avUser = _FileListToArray(@ScriptDir, "*.au3")
$sFile = @ScriptDir & "\test.txt"
FileDelete($sFile)

; Write first array to file by string file name
__FileWriteFromArray($sFile, $avCommon, 0, 0, @ScriptDir & "\")

; Open file and append second array
$hFile = FileOpen($sFile, 1) ; 1 = append
__FileWriteFromArray($hFile, $avUser, 0, 0, @ScriptDir & "\")
FileClose($hFile)

; Display results
Run("notepad.exe " & $sFile)


; Modified
Func __FileWriteFromArray($File, $a_Array, $i_Base = 0, $i_UBound = 0, $Location = "")
    ; Check if we have a valid array as input
    If Not IsArray($a_Array) Then Return SetError(2, 0, 0)

    ; determine last entry
    Local $last = UBound($a_Array) - 1
    If $i_UBound < 1 Or $i_UBound > $last Then $i_UBound = $last
    If $i_Base < 0 Or $i_Base > $last Then $i_Base = 0

    ; Open output file for overwrite by default, or use input file handle if passed
    Local $hFile
    If IsString($File) Then
        $hFile = FileOpen($File, 2)
    Else
        $hFile = $File
    EndIf
    If $hFile = -1 Then Return SetError(1, 0, 0)

    ; Write array data to file
    Local $ErrorSav = 0
    For $x = $i_Base To $i_UBound
        If FileWrite($hFile, $Location & $a_Array[$x] & @CRLF) = 0 Then
            $ErrorSav = 3
            ExitLoop
        EndIf
    Next

    ; Close file only if specified by a string path
    If IsString($File) Then FileClose($hFile)

    ; Return results
    If $ErrorSav Then
        Return SetError($ErrorSav, 0, 0)
    Else
        Return 1
    EndIf
EndFunc   ;==>__FileWriteFromArray

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
ajit

@valuator

Thanks so much; it worked perfect.

Regards

Ajit

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
Sign in to follow this  

×