Notifications
Clear all

[Closed] Listbox with foldernames

Hallo,

I try to wrote a script.
I need a Listbox with all Folder in an directory.(only the Foldername)
I found this one which list all subdirectories with th complete path.

function GetAllSubDirs_fn MyDirectory =

(
temp = #();
s = 1;
folders = getDirectories (MyDirectory + “/“);
t = folders.count;
while s < t do
(
for i = s to t do (temp = getDirectories (folders[i]+”
”);
for j = 1 to temp.count do folders[folders.count+1] = temp[j] );

s = t;
t = folders.count;
)
sort folders

return folders;
)

—Can someone help me?

4 Replies

I didn’t double check in max, but i think this should work:

function GetAllSubDirs_fn MyDirectory =
(
	temp = #()
	s = 1
	folders = getDirectories (MyDirectory + "/*")
	t = folders.count
	while s < t do
	(
		for i = s to t do (temp = getDirectories (folders[i]+"*")
		for j = 1 to temp.count do folders[folders.count+1] = temp[j] )

		s = t
		t = folders.count
	)
	sort folders

	-- this part gets you only the last part of the path
	for a=1 to folders.count do
	(
		folders[a] = filterstring folders[a] "\\"
		folders[a] = folders[a][folders[a].count]
	)

	folders
)

GetAllSubDirs_fn @"C:\Users\"

Thank you,

works perfectly…

 MZ1

fn GetAllSubDirs_fn MyDirectory =
(
for F in (getdirectories (MyDirectory+”*”)) collect (trimright (pathConfig.stripPathToLeaf F) “\”)
)

GetAllSubDirs_fn “E:\Music\”

Thank You very much Mehdi.

Very short compact function.