Jump to content
Sign in to follow this  
Superbrka

_FileListToArrayRec and subfolders filter

Recommended Posts

Hi,

Is there any way to set up folder filter in _FileListToArrayRec() to get following array ?

Folder structure:
C:.
├───Folder_1
│   └───Job_1
│       └───SUBFOLDER_1
├───Folder_2
│   └───Job_1
│       └───SUBFOLDER_1
└───Trash

 

And what i want to have in array is only:

C:\Temp\Folder_1\Job_1
C:\Temp\Folder_2\Job_2

 

Any help is going to be appreciated.

Bye

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

Local $dir="C:\Temp"

DirCreate("C:\Temp\TRASH")
DirCreate("C:\Temp\Folder_1\Job_1\SUBFOLDER_1")
DirCreate("C:\Temp\Folder_2\Job_1\SUBFOLDER_1")

$FOLDER_ARRAY = _FileListToArrayRec($dir, "*", $FLTAR_FOLDERS, -1, $FLTAR_FASTSORT, $FLTAR_FULLPATH)

_ArrayDisplay($FOLDER_ARRAY)

 

Share this post


Link to post
Share on other sites
#include <File.au3>
#include <Array.au3>

Local $dir="C:\Temp"

DirCreate("C:\Temp\TRASH")
DirCreate("C:\Temp\Folder_1\Job_1\SUBFOLDER_1")
DirCreate("C:\Temp\Folder_2\Job_1\SUBFOLDER_1")

$FOLDER_ARRAY = _FileListToArrayRec($dir, "*", $FLTAR_FOLDERS, -1, $FLTAR_FASTSORT, 1)
;_ArrayDisplay($FOLDER_ARRAY)

Local $res[0]
For $i = 1 to $FOLDER_ARRAY[0]
    (StringInStr($FOLDER_ARRAY[$i], "\") <> 0) ? _ArrayAdd($res, $dir & "\" & $FOLDER_ARRAY[$i]) : 0
Next
_ArrayDisplay($res)

:)

Share this post


Link to post
Share on other sites

Hello,

Thanks for the replay.

But, what if a second subfolders are randomly named (Like, instead "Job_1" -> "123", "abc", "9a9" ) ?
Is there a way to get a list ?

Thanks in advance for your help

 

Share this post


Link to post
Share on other sites
2 hours ago, Superbrka said:

what if a second subfolders are randomly named

Then you will need a 2nd step - something like my previous code or so  :rolleyes:

Share this post


Link to post
Share on other sites

Thank you, that was my first solution as well but, the speed is "quite slow" i thought it would be faster with the some filter setup.

Maybe someone knows other solution? There must be a (fast) way to get a list of subfolder structure up/from to a certain level, or not ?

Thanks

Share this post


Link to post
Share on other sites

Try not sorting in the _FileListToArrayRec call, but after.  This may speed it up, depending on how large the path tree is.  From the help file for _FileListToArrayRec.  

Quote

Sorting the results will significantly increase the time required for the UDF to return the array.

 

Adam

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  

×
×
  • Create New...