Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simplest way to get the equivalent of "find ." in python?

What is the simplest way to get the full recursive list of files inside a folder with python? I know about os.walk(), but it seems overkill for just getting the unfiltered list of all files. Is it really the only option?

like image 884
static_rtti Avatar asked Sep 14 '12 08:09

static_rtti


1 Answers

pathlib.Path.rglob is pretty simple. It lists the entire directory tree

(The argument is a filepath search pattern. "*" means list everything)

import pathlib


for path in pathlib.Path("directory_to_list/").rglob("*"):
    print(path)
like image 77
Miłosz Łakomy Avatar answered Sep 19 '22 21:09

Miłosz Łakomy