Skip to content

Instantly share code, notes, and snippets.

@gustavorv86
Created March 27, 2019 15:22
Show Gist options
  • Save gustavorv86/d4c41e374fde7921fcfa7854082ed758 to your computer and use it in GitHub Desktop.
Save gustavorv86/d4c41e374fde7921fcfa7854082ed758 to your computer and use it in GitHub Desktop.
Python get all path files (not directories) of a directory recursively
#!/usr/bin/env python
import os
import sys
def _r_get_files(parent_dir, list_files):
for child_name in os.listdir(parent_dir):
## Ignore directories
# if child_name == ".git":
# continue
child_path = os.path.join(parent_dir, child_name)
if os.path.isfile(child_path):
list_files.append(child_path)
if os.path.isdir(child_path):
_r_get_files(child_path, list_files)
return
def get_files(parent_dir):
list_files = list()
_r_get_files(parent_dir, list_files)
return list_files
def main(args):
if len(args) > 1 and os.path.isdir(args[1]):
all_files = get_files(args[1])
for path_file in all_files:
print(path_file)
if __name__ == "__main__":
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment