queensoft Posted January 9 Share Posted January 9 (edited) _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). What I need: each subfolder placed in a separate array, inside a 2 dimensions array - see second image (blue text). Thanks. PS: what's up with the "Max total size: 40.59 kB" for attachments??? Edited January 9 by queensoft Link to comment Share on other sites More sharing options...
Nine Posted January 9 Share Posted January 9 (edited) 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 January 9 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
queensoft Posted January 9 Author Share Posted January 9 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 More sharing options...
rudi Posted January 23 Share Posted January 23 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 More sharing options...
queensoft Posted January 23 Author Share Posted January 23 (edited) 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. Script: #include <File.au3> #include <Debug.au3> $a = _FileListToArrayRec('D:\77777777\', Default, Default, 1, 1, 2) _DebugArrayDisplay($a) Result: image2 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 January 23 by queensoft Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 23 Moderators Share Posted January 23 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 queensoft 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
rudi Posted January 23 Share Posted January 23 ... 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 More sharing options...
queensoft Posted January 23 Author Share Posted January 23 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 More sharing options...
Nine Posted January 23 Share Posted January 23 (edited) 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 January 23 by Nine made the code queensoft 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
queensoft Posted January 23 Author Share Posted January 23 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 More sharing options...
Nine Posted January 23 Share Posted January 23 Glad you like it. I will sure use it from time to time. It is simple and fast. queensoft 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now