Jump to content

_FileListToArray question


Recommended Posts

Hi,

If I used _FileListToArray to get some file names...

Lets say we have like 5 files in "C:\Test"

Example

$Path = "C:\Test\"
$File = _FileListToArray($File, "*", 1)

MsgBox(0, "", $File[1])

So $File[1] will be the first file.

So how can I get the name into a msgbox?

AlmarM

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Ok, this works.

#include <Array.au3>
#include <File.au3>

DirCreate("C:\AlmarM\")

$Path = "C:\AlmarM\"

FileWrite($Path & "test1.txt", "test1")
FileWrite($Path & "test2.txt", "test2")
FileWrite($Path & "test3.txt", "test3")
FileWrite($Path & "test4.txt", "test4")

$File = _FileListToArray($Path)
_ArrayDisplay($File)

MsgBox(0, "", $File[2])

Func OnAutoItExit()
    FileDelete($Path & "test1.txt")
    FileDelete($Path & "test2.txt")
    FileDelete($Path & "test3.txt")
    FileDelete($Path & "test4.txt")
    DirRemove($Path)
EndFunc

I think im just stupid and I missing something ^_^

AlmarM

EDIT: Typo

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Because $File[2] is still an array.

#include <Array.au3>
#include <File.au3>

Dim $SubItem[9], $File[9]

;$Path = "C:\Documents and Settings\Gortstraat_41\Bureaublad\GM handbook v62\GM Handbook v62\"
$Path = @ScriptDir

$SubItem[0] = $Path & "Character\"
$SubItem[1] = $Path & "Character\Equips"
$SubItem[2] = $Path
$SubItem[3] = $Path & "Items"
$SubItem[4] = $Path & "Maps, portal"
$SubItem[5] = $Path & "Misc"
$SubItem[6] = $Path & "NPC"
$SubItem[7] = $Path & "Pet"
$SubItem[8] = $Path & "Monsters"

For $i = 0 To 8
    $File[$i] = _FileListToArray($SubItem[$i], "*", 1)
Next

_ArrayDisplay($File[2])

Edit: Trying to access the values in the array with something like

msgbox(0,"",$File[2][0])

resulted in error. Reading the help-file I found:

"It was said that an Array contains only one datatype of the same type. But technically speaking, a Variant in AutoIt can contain anything from a number to a boolean value. So an AutoIt-Array could also contain different types, even other Arrays. This has not been strictly forbidden in AutoIt. However, it is NOT ADVISABLE to mix different datatypes in an Array. Especially the use of an Array inside another Array will severely affect the execution speed of your script."

So I suggest you better switch to use a single array...

#include <Array.au3>
#include <File.au3>

Dim $SubItem[9],$Filelist_Total[1]

;$Path = "C:\Documents and Settings\Gortstraat_41\Bureaublad\GM handbook v62\GM Handbook v62\"
$Path = @ScriptDir & "\"

$SubItem[0] = $Path & "PHP\"
$SubItem[1] = $Path & "Character\Equips"
$SubItem[2] = $Path
$SubItem[3] = $Path & "Items"
$SubItem[4] = $Path & "Maps, portal"
$SubItem[5] = $Path & "Misc"
$SubItem[6] = $Path & "NPC"
$SubItem[7] = $Path & "Pet"
$SubItem[8] = $Path & "Monsters"


For $i = 0 To 8
    $Filelist_Single = _FileListToArray($SubItem[$i], "*", 1)
    if IsArray($Filelist_Single) and UBound($Filelist_Single) > 1 then 
        ReDim $Filelist_Total[UBound($Filelist_Total)+UBound($Filelist_Single)-1]
        $Filelist_Total[0] += $Filelist_Single[0]
        for $n = 1 to UBound($Filelist_Single)-1
            $Filelist_Total[UBound($Filelist_Total)-UBound($Filelist_Single)+$n] = $Filelist_Single[$n]
        Next
    endif
Next

_ArrayDisplay($Filelist_Total)

And I'll bet there are solutions with a better performance out there ^_^...

Edited by KaFu
Link to comment
Share on other sites

Ye, thats the problem... I want all the paths including the files...

$SubItem[0] & $File[0]

Should return

C:\Documents and Settings\Gortstraat_41\Bureaublad\GM handbook v62\GM Handbook v62\xxxx.txt

AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Link to comment
Share on other sites

Hi.

Use this UDF: "_FileListToArray3.au3".

#include "c:\install\FileListToArray3\FileListToArray3.au3"
#include <array.au3>

$Path="C:\Windows\system32"

$System32=_FileListToArray3($Path,"*",1, 1, 1) ; *=filter; 1=files only; 1=recurse; 1=return full path and filename
_ArrayDisplay($system32)

Regards, Rudi.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

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...