Dict Folders&files

manmusic's icon

I would like to have a dictionary that lists subfolders and the files related to them. I manage to get either the folders or the files but not both.

forders&files.json
application/json 5.78 KB

Source Audio's icon

umenu is better for that
connect zl.slice if you don't want numbering inserted

Max Patch
Copy patch and select New From Clipboard in Max.

manmusic's icon

THANKS! but that's not what I'm looking for. I misspoke

I want to obtain a dictionary with the folders in key and the files in value:

{

"folders1" : {

"subFolder" :  "file1",

"subFolder" :  "file2",

"subFolder" :  "fileX",

.../...

}

}

I would then like to extract the data from the dictionary to two synchronized umemu. A folder menu and a file menu.

Roman Thilenius's icon

i would use 1 dictionary for displaying, and another one (or an umenu) which is not shown to the user and contains the full paths to the subfolders.

then you can operate it in two steps; first get all subfolders in the chosen folder, then get all files in these subfolders. in this case one by one, so that you can build a dict from them where these filenames are ordered into the correct "subfolder".

to open a single file you can now build the path to open by the stored path and the first two level of the dict content.

for one subfolder level only, a coll might do the same though.

Source Audio's icon

You don't need a dict for that,
set 1 umenu to list folders only, using depth(subfolders) as you wish,
and select a folder from it as prefix for 2nd umenu.

You would do something similar to combine stuff into dict, but why double work ?

anyway, I am sure you will find your way by reading help file and reference if you still want to use dict.
the challenge is to convert folder paths to keys and arrays for files inside.

in addition, if you want to use menus at the end to load files, you must preserve full path.

manmusic's icon

Indeed, I want to list all the files present in a folder that contains multiple subfolders. I would like to use a table where the first column lists the folders and the next column lists the files they contain.

Roman Thilenius's icon

speaking of "columns", and if it is really only about displaying - and maybe click-selecting - stuff, you might want to look into jit.cellblock, too.

it can be synchronized to a coll, which then serves as hidden storage for the full path and offers im- and export features.

manmusic's icon

I am not looking for a jit.cellblock table, but rather a spreadsheet-like list with X comments (subfolder names) on the left and clickable umenus on the right to select files and send them to the correct audio player.

FOO(subFolder)
-dewey (file1)
-louis (file2)
-huey (.../...)

PHY(subFolder)
-luis (file1)
-harvey (file2)
-albert (.../...)

Source Audio's icon

I don't know which max object can offer both display
and clickable item that can output folder path in such form.
if you manage to stuff that into dict, how do you display it and select?

only thing I can think off is chooser or jit.cellblock
listing folder hiearchy in list form:

main/sub1/aaa
main/sub1/bbb
main/sub2/1abc
main/sub2/2abc/extra
...

Roman Thilenius's icon

i am doing this using a bpatcher based on 2 umenus: one holds the names of files which were selected before the usual ways, drag and drop, opendialog,...), and a hidden one which stores the full paths to the files.

the same method could be used around cellblock, dict, coll, textentry, messagebox...

for large amount of data i can see why one would prefer dict.view as a kind of filebrowser.

manmusic's icon

The ideal would be two Umenu for me:

Max Patch
Copy patch and select New From Clipboard in Max.