Jump to content
Sign in to follow this  
AlmarM

_FileListToArray question

Recommended Posts

AlmarM

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.

Share this post


Link to post
Share on other sites
ShawnW

$File = _FileListToArray($Path, "*", 1)

not

$File = _FileListToArray($File, "*", 1)

other than that I don't know what problem you are having because that should already display the name in a message box

Share this post


Link to post
Share on other sites
Valuater

Alarm = 888 posts

Shawn = 2 posts

.... Hmmm, wonder who reads and uses the help file??

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
ShawnW

Alarm = 888 posts

Shawn = 2 posts

.... Hmmm, wonder who reads and uses the help file??

8)

was that comment against me and my lack of post?

cause his code = fail

my code = 4 da win

Share this post


Link to post
Share on other sites
Valuater

was that comment against me and my lack of post?

cause his code = fail

my code = 4 da win

No Shawn, not at all.

His code = fail when he has 888 posts

your code = 4 da win with only having two posts

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
John117

hahaha 4 da win :-)

I think he just made a goof and mixed up the $Variables . . .

Easy enough todo . . . for me anyway ;-)

Edited by Hatcheda

Share this post


Link to post
Share on other sites
AlmarM

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.

Share this post


Link to post
Share on other sites
KaFu

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

Share this post


Link to post
Share on other sites
AlmarM

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.

Share this post


Link to post
Share on other sites
rudi

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!

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.