Can you make Julia's readdir() function differentiate files from directories?

Viewed 271

Julia's readir lists a directory but it doesn't say if the items are files or directories. Is there any way to toggle this?

1 Answers

readdir gets the names of everything in the current directory. We can use isdir or isfile to filter it down.

# Get all directories
filter(isdir, readdir())
# Get all files
filter(isfile, readdir())
# Return a tuple consisting of the filename and whether or not it's a directory
map((x) -> (x, isdir(x)), readdir())
Related