Listing directories #4038
-
Hello, I've searched for some documentation and discussions on this, but I can't find anything that answers my question: I want to get a list of directories from file.ls. It should be fairly easy by using list.iter and file.is_directory. I can get the directory entry, but I want to add this to a list and I keep getting type errors when I use list.add(directory, list). How can I get around this? I was making the target list a string, but maybe that's where the trouble is? If I use an empty list to start, the same problem occurs. Any help would be great, Thanks in advance! A. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Without looking at your code it's hard to give more help! |
Beta Was this translation helpful? Give feedback.
So,
list.iter
does not produce any result, it justs applies the function given as argument and discards its result.You can do one of two things:
This is the most straight forward:
This is the most advanced/functional way. Hard to understand at first but very powerful. You can use
list.fold
for that, it accumulates the result of applying the reduce function over and over: