Skip to content
Snippets Groups Projects

recursively list files in directory based on fileformat

  • Clone with SSH
  • Clone with HTTPS
  • Embed
  • Share
    The snippet can be accessed without any authentication.
    Authored by Magnus Maria Hoffmann
    Edited
    snippetfile1.txt 310 B
    from pathlib import Path
    
    # recursively read in files, only works in python 3.5+
    # works on linux & windows returns files w/ directory
    def list_files_recursively(directory, fileformat):
        glob_path = Path(directory)
        file_list = [str(pp) for pp in glob_path.glob("**/*."+fileformat)]
        return file_list
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Please register or to comment