Links

List specific files from directory and subdirectories

Tags: #python #glob #os #files #directory #subdirectories
Author: Florent Ravenel​
Last update: 2023-05-31 (Created: 2023-05-31)
Description: This notebook list all specific files from a directory and its subdirectories using glob and os libraries. It is usefull to quickly list all files from a directory and its subdirectories.
References:

Input

Import libraries

import glob
import os

Setup Variables

  • directory: path of the directory to list files
  • file_extension: extension of the files to list
directory = "./"
file_extension = "txt"

Model

List files from directory and subdirectories

files = glob.glob(os.path.join(directory, "**/*." + file_extension), recursive=True)

Output

Display result

files