Sign in to follow this  
Followers 0
Faalamva

What am I doing wrong with _FileListToArray ?

12 posts in this topic

Hi, here's the deal :

I have a directory D:Test in which I have more than 1700 subdirectories, all named 2013XXXXXXXX (the blurred parts may contain letters and figures) :

874607Test.jpg

I'd like to check that the main directory doesn't contain any 2014* subdirectories.

I have written the following test program :

$Folders = _FileListToArray("D:\Test\", "2014*", 2)
MsgBox(0, "", $Folders[0])
For $i = 1 To $Folders[0]
    ConsoleWrite($i & " : " & $Folders[$i] & @CRLF)
Next

Strangely, the MsgBox returns 5 occurrences found ! :shocked:

And the list returned is something like :

1 : 20130521_214630_XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
2 : 20130330_110444_XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3 : 20130331_111940_XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
4 : 20130117_194957_XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5 : 20130407_172611_XXXXXXXXXXXXXXXXXXXXXXXXXXXXX

These occurrences don't begin with 2014 (and don't contain 2014 either).

So it seems the 2014* filter doesn't work properly, or am I missing something ? :think:

Thanks !

Share this post


Link to post
Share on other sites



Faalamva,

As mentioned in the Help file, _FileListToArray uses Windows to search for files and it has been shown that wildcards can sometimes return strange results. :(

Please try using _FileListToArrayRec (without the recur flag) as that uses a RegEx to search and is a little more strict in its wildcard observance - albeit at the cost of speed. Perhaps that will do better: ;)

$Folders = _FileListToArrayRec("D:\Test\", "2014*", 2)
MsgBox(0, "", $Folders[0])
For $i = 1 To $Folders[0]
    ConsoleWrite($i & " : " & $Folders[$i] & @CRLF)
Next
Let me know how you get on - I do not really want to have to create 1700 folders to test it myself. :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

@Faalamva, for your specific purpose, try this:

If FilesExist('D:\test\2014*') Then
    MsgBox(0,'result:','found file(s) or folder(s).')
Else
    MsgBox(0,'result:','did not find file(s) or folder(s).')
EndIf

Func FilesExist($sMask)
    Local $hSearch=FileFindFirstFile($sMask)
    Local $sFile
    $sFile=FileFindNextFile($hSearch)
    If @error Then
        Return False
    Else
        Return True
    EndIf
EndFunc

that is my take on FileExists() which i always ranted about it not supporting wildcards...

@Melba23:

For $i=1 To 1700
    DirCreate('D:\Test\2013_'&$i)
Next

:-)

Share this post


Link to post
Share on other sites

_FileListToArray uses FileFindFirstFile and FileFindNextFile to find the files to put into the array, I don't think that snippet is going to do any better than the UDF.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

orbs,

That will not reproduce the OP's folder structure and so would be of no use at all. ;)

M23

Edited by Melba23
Speeling

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

_FileListToArray uses FileFindFirstFile and FileFindNextFile to find the files to put into the array, I don't think that snippet is going to do any better than the UDF.

 

true, but that snippet calls FileFindNextFile only once, while the UDF calls it repeatedly as long as there are any files out there that fit the mask.

 

orbs,

That will not reproduce the OP's folder structure and so would be of no use at all. ;)

M23

 

i was just kidding, i bet if you wanted to do that, it would take you about 13 seconds to script it - including power-on your pc, which takes ~12 of those seconds :-)

Share this post


Link to post
Share on other sites

Thank you all for your replies.

I have modified the script and run some tests.

Note : First I had to figure out why _FileListToArrayRec couldn't be found despite the correct include.

For those that may meet the same problem, just install AutoIt 3.3.10.1 (I was using the 3.3.8.1 version, which doesn't include _FileListToArrayRec natively in File.au3).

So, here's the new script :

#include <File.au3>

$Folders = _FileListToArrayRec("D:\Test\", "2014*", 2)
MsgBox(0, "", "@error returned is : " & @error)

If @error = 9 Then
    MsgBox(0, "", "No occurrence found")
Else
    MsgBox(0, "", $Folders[0])
    For $i = 1 To $Folders[0]
        ConsoleWrite($i & " : " & $Folders[$i] & @CRLF)
    Next
EndIf

For some strange reason :

- if I apply the 2013* mask, @error = 0 and all my folders are correctly returned.

- if I apply the 2014* mask, @error = 1 and my program crashes (it's normal since $Folders[0] in this case is undefined).

But I can't explain why @error = 1 ?? According to the help file, @error = 1 means "Path not found or invalid"... And I'm pretty positive that D:Test exists (tested with or without trailing ""...) ! :doh:

Any thoughts ? :sweating:

Share this post


Link to post
Share on other sites

The previous code has also been tested on orbs' version of test directory, created by using :

For $i=1 To 1700
    DirCreate('D:\Test\2013_'&$i)
Next

The result is the same :

- The filter 2014* returns @error = 1 !!  :x

- whereas the filter 2013* returns @error = 0 !!

Share this post


Link to post
Share on other sites

true, but that snippet calls FileFindNextFile only once, while the UDF calls it repeatedly as long as there are any files out there that fit the mask.

Understandable, but what I was saying is that the filtering for _FLTA is the same as what you posted, so even if the OP were to use it with 2014*  as the filter you'd get the same results as _FLTA.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Faalamva,

You are confusing @error - which is set to 1 for all errors - and @extended - which in the "2014*" case is being set to 9 to indicate that no results were found, which is exactly what happens. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Thank you Melba23 !!

:cheer: The code is finally working as expected ! :cheer:

#include <File.au3>

$Folders = _FileListToArrayRec("D:\Test\", "2013*", 2)

If @error = 1 And @extended <> 9 Then
    MsgBox(0, "", "An error occured : @extended = " & @extended)
ElseIf @error = 1 And @extended = 9 Then
    MsgBox(0, "", "No folders found")
ElseIf @error = 0 Then
    MsgBox(0, "", $Folders[0] & " occurrences found")
EndIf
Edited by Faalamva

Share this post


Link to post
Share on other sites

Faalamva,

Glad we got it working. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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  
Followers 0