Replacement for os.path.walk in Python?

question

#1

Hi Folks,

I am new to Julia, and beginning to port some machine learning projects over to Julia. One thing I am missing is the python os library which can walk a directory path quite easily. I am googling around and looks like it doesn’t exist in Julia yet… but wanted to throw up a question before I start writing my own implementation

for context here’s the python function I’m porting

import os
import fnmatch

def list_all_files(directory, extensions=None):
    for root, dirnames, filenames in os.walk(directory):
        for filename in filenames:
            base, ext = os.path.splitext(filename)
            joined = os.path.join(root, filename)
            if extensions is None or ext.lower() in extensions:
                yield joined

Thank you


#2
help?> walkdir
search: walkdir

  walkdir(dir; topdown=true, follow_symlinks=false, onerror=throw)

  The walkdir method returns an iterator that walks the directory tree of a directory. The iterator returns a tuple containing (rootpath, dirs, files). The directory tree can be traversed top-down or
  bottom-up. If walkdir encounters a SystemError it will rethrow the error by default. A custom error handling function can be provided through onerror keyword argument. onerror is called with a
  SystemError as argument.

  for (root, dirs, files) in walkdir(".")
      println("Directories in $root")
      for dir in dirs
          println(joinpath(root, dir)) # path to directories
      end
      println("Files in $root")
      for file in files
          println(joinpath(root, file)) # path to files
      end
  end