Acces Directory contents + folders

Hi community,

I’m looking for something similar as the component directory contents from human plugin. Basically what it does, is allow you to scroll through the files you have in the folder. BUT what this component didn’t do is showing the folders inside this main folder and let you select them…

I found the source code in C# to do it, but I don’t know C# either python to do something like that…

Thank you :wink:

Best,

-CC

1 Like

This seems to be doing the trick:

2 Likes

Thank you @ivelin.peychev ! Almost there


the thing is it gives you everthing that are in the sub folders. When I have alot of files in the subfolders it crashes. Anything to only see the content of the inputted folder ?

-CC

That’s even simpler. I assumed you want subfolders’ content

a = Directory.GetFiles(x)
1 Like

I think this is neater. :wink:

looks awesome ! thank Ivelin !

Best,
-CC

It was my pleasure, I actually learnt how to do it while helping you :smiley:

LAst question :slight_smile: For instance, how to get both (files and directories in output a), then only directories in output b, and files in output b ?? ^^

-CC

You can see I left the other two options commented.

a = Directory.GetDirectories(x) #this will list only the folders in the path
b = Directory.GetFiles(x) # this will give you the files inside the path
c = Directory.GetFiles(x, "*",SearchOption.AllDirectories) # this will give you all files and folders including subfolders. Everything inside the path. You can change "*" to "*.txt" and it will list all directories/subdirectories and files with extension txt.

If you zoom in the component you’ll see little + signs you can add outputs “b” and “c” there.

I hope this helps

1 Like

is there something like :

a = Directory.GetDirectories(x) AND Directory.GetFiles(x)

so in output «a» you don’t have all the subfolders .

Ah… I need to take a python script cours… definitly

Best,
-CC

You can create a loop of some sort.

a = [] # define a as empty list
dir = Directory.GetDirectories(x) #define variable dir containing list of all directories
files = Directory.GetFiles(x) # define variable files containing list of all files

for d in dir:
    a.append(d) # adding the contents of dir into a (the folders)
for f in files:
    a.append(f) # adding the contents of files into a (the files)

Though at the end I don’t know how to sort list a. You’ll just get a list of first all folders and then all files. (that is files in the path, without subfolders)

I did not test it. I’ll test it when I find some more time.

It works :), hopefully this is what you wanted.

GH.FilesFolders_in_path.gh (12.4 KB)

In fact done like that, you can reuse the script for each consecutive sub-folder level

3 Likes

Ahh there you go !! exactly what I was looking for !

Thanks for the help and time @ivelin.peychev. I apreciate

-Charles C.

2 Likes