# Replacement for os.path.walk in Python?

**URL:** https://discourse.julialang.org/t/replacement-for-os-path-walk-in-python/8887
**Category:** Machine Learning
**Tags:** question
**Created:** [February 7, 2018, 10:09am UTC](https://discourse.julialang.org/t/replacement-for-os-path-walk-in-python/8887 "2018-02-07T10:09:25Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![amarbl](https://avatars.discourse-cdn.com/v4/letter/a/cdc98d/32.png) [@amarbl](https://discourse.julialang.org/u/amarbl)
#### Post date: [February 7, 2018, 10:09am UTC](https://discourse.julialang.org/t/replacement-for-os-path-walk-in-python/8887/1 "2018-02-07T10:09:25Z")

</div>

Hi Folks,

I am new to Julia, and beginning to port some [machine learning](https://mindmajix.com/machine-learning-training) 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

```python
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

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [February 7, 2018, 12:00pm UTC](https://discourse.julialang.org/t/replacement-for-os-path-walk-in-python/8887/2 "2018-02-07T12:00:14Z")

</div>

```julia
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

```
