3

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?

cybervigilante
  • 231
  • 1
  • 5

1 Answers1

3

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())
Silvio Mayolo
  • 62,821
  • 6
  • 74
  • 116
  • Thanks. I should have mentioned it was Windows, which won't accept all run commands, but got a full listing showing files and directories with run(`cmd /C dir`) - however, filter is more generally handy. – cybervigilante Jul 05 '21 at 04:35
  • Looks like the editor removed the backticks from the run command. – cybervigilante Jul 05 '21 at 04:45