Jump to content

_FileListToArrayRec - but each subfolder is returned in separate array dimension


Recommended Posts

_FileListToArrayRec - Return Value: a one-dimensional array made up as follows: simple list of all files and subfolders together - see first image attached (red text).

Image3.jpg

What I need: each subfolder placed in a separate array, inside a 2 dimensions array - see second image (blue text).

Image2.jpg

Thanks.

 

PS: what's up with the "Max total size: 40.59 kB" for attachments???

 

Edited by queensoft
Link to comment
Share on other sites

  • queensoft changed the title to _FileListToArrayRec - but each subfolder is returned in separate array dimension

Here my generic 1d to 2d procedure :

#include <Array.au3>

; 1d to 2d resize arrays

Local $a = [0, 0, 0, 1, 2, 3, 4, 5, 6, 7]

$a = _Array_Resize($a, 2, 2, False)
_ArrayDisplay($a, "Test")

Func _Array_Resize(ByRef $aArray1d, $iColumns, $iStart = 0, $bLine = True)
  If $iStart = Default Then $iStart = 0
  If $bLine = Default Then $bLine = True
  Local $iElements = UBound($aArray1d) - $iStart
  If Mod($iElements, $iColumns) Then Return SetError(1, 0, False)

  Local $aArray2d[$iElements / $iColumns][$iColumns]

  For $i = $iStart To UBound($aArray1d) - 1
    If $bLine Then
      $aArray2d[Floor(($i-$iStart)/$iColumns)][Mod($i-$iStart, $iColumns)] = $aArray1d[$i]
    Else
      $aArray2d[Mod($i-$iStart, $iElements / $iColumns)][Floor(($i-$iStart)/ $iElements * $iColumns)] = $aArray1d[$i]
    EndIf
  Next
  Return $aArray2d
EndFunc   ;==>_Array_Resize

ps.  Everyone has a limited amount of space for attachments.  You seem to be reaching the maximum.  So you will need to delete old attachments from your history of activity.

Edited by Nine
Link to comment
Share on other sites

Generic split doesn't work.

In my example, there are 2 subfolders with 4 files each, that's easy.

But in reality, there are X subfolders  with 0-YYYYYY files each.

I already have a workaround in place (first find subfolders only, then find files for each subfolder).

But I was thinking of an all-in-one function: search files / folders, return 1D / 2D array.

 

PS: Thanks for the attachment tip.

Link to comment
Share on other sites

  • 2 weeks later...

Hi,

in your OP you were talking of an "array-of-arrays" (that's a 1D array holding array elements), is that what you want, or are you looking for a 2D array?

Perhaps you want to describe the task to be solved, maybe there is an easier approach do solve it?

 

Rudi.

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

Link to comment
Share on other sites

Doesn't matter how it's returned. I just want an easy way to get each sub-folder.

Regular way seems to work OK, but I need to add additional steps to extract the result.

See attached image1.

Image1.jpg.43d8684ff8e369382cc73f5625c64377.jpg

Script:

#include <File.au3>
#include <Debug.au3>
$a = _FileListToArrayRec('D:\77777777\', Default, Default, 1, 1, 2)
_DebugArrayDisplay($a)

Result: image2

Image2.jpg.02a64a3cf2575510227bc646f812a2b7.jpg

Now, in order to parse this array, I need to use different methods, with extra steps.

Let's say, first one that comes to mind: elements #1, #3, #9, #11 are folders, so everything after that AND before next one are files inside that folder.

OR, different method: if last character is NOT \, then it's a file, then extract folder from full path, separate by folders.

Now, if I get the result as an "array of arrays" (again, doesn't matter exactly how, just need it already separated by folders), it would be much easier.

Right now, the script is working just fine, using above method (first find subfolders only, then find files for each subfolder), it's just a matter of optimisation....

Edited by queensoft
Link to comment
Share on other sites

  • Moderators

queensoft,

Back before I wrote the _FileListToArrayRec function, people were clamouring for a single function to return a single listing (with suitable filters) rather than having to recursively list each subfolder and then list the files within them. So the recursive function was added to the standard library (after a fair amount of, at times, heated discussion) to return the consolidated list. 

As a matter of interest the sorting part of the recursive function internally splits the single returned list into separate folders to help in sorting - the recursively found folders and files  within them are not necessarily returned in the expected order and so need to be extracted and reordered. You might well be able to modify that code to return an "array of arrays" where each element holds the content of a single subfolder - but forget the standard function itself being modified to do that!

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

... and *WHAT* are you going to do with all the "files-per-folder" ?

Possibly it's easier just to get all the folders, then process folder by folder the files in that one?

What recurse deepth will you have to process?

Can you process each folder independently, or does content for folder A change the rules for processing files in folder B?

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

Link to comment
Share on other sites

Melba23 > Thanks for the reply.

I was looking for an already create function / UDF / script or for someone to whip one out quickly.

I have a working script, I can turn it into a proper function, but, if it work.... don't touch it.

So let's just say, from my part, problem is 99% solved.

 

rudi > files-per-folder list: process all files, from each folder separately.

For my script, I need to have each folder separately.

Recurse depth: unlimited

Process rules: same for any folder / file, just easier (FOR ME) if they are separated from the start.

Link to comment
Share on other sites

Another approach would be to create a map of array where each key is the folder name and the array is the list of file names within that folder...Would be kind of nice to have it.

Well, it seems I found my idea too tempting :

#include <Array.au3>

Opt("MustDeclareVars", True)

Global $mList[]

FileListRecToMap($mList, "C:\Apps\AutoIt\Files\")
For $sKey In MapKeys($mList)
  _ArrayDisplay($mList[$sKey], $sKey)
Next

Func FileListRecToMap(ByRef $mList, $sFolder)
  Local Static $oShell = ObjCreate("Shell.Application")
  Local $oFolder = $oShell.NameSpace($sFolder)
  If Not IsObj($oFolder) Then Return 1
  Local $oFolderItems = $oFolder.Items()
  $oFolderItems.Filter(0x40, "*")
  Local $aList[$oFolderItems.count], $i = 0
  For $oFile In $oFolderItems
    $aList[$i] = $oFile.name
    $i += 1
  Next
  $mList[$sFolder] = $aList
  $oFolderItems.Filter(0x20, "*")
  For $oFolderItem In $oFolderItems
    FileListRecToMap($mList, $oFolderItem.path)
  Next
EndFunc   ;==>FileListRecToMap

 

Edited by Nine
made the code
Link to comment
Share on other sites

Yes, that seems to be what I was looking for.

I don't fully understand how it works (MapKeys, for instance), but I'll take it.

$mList[$sKey] = contains the files

$sKey = is the folder

I'm happy with it. Thank you.

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