How do I list all files and directories in a directory in Julia?

Viewed 1336

In Python, I could use:

from os import listdir
os.listdir()

In Julia, how can I list everything inside a given directory?

1 Answers
readdir()

This lists all files and in a current directory folder as Vector{String}

Of course you can provide directory name:

readdir("dir/name")

On Windows a useful practice is raw String macro:

readdir(raw"c:\temp")

If you want to see what is in subdirectories use walkdir:

items = [item for item in walkdir("some/path")]

This walks through whole directory tree and returns a Vector of 3-element tuples where first element is directory, second list of it subdirectories and the third the list of files in a directory.

Related