Updated: 21 dec 2025
This code walks through a specified folder and all subfolders to identify the kind of files that are present. It returns the extensions.
import os
directory = '..'
def find_file_extensions(directory):
extensions = set() # Used to exclude duplicates
# Iterate over all files in the specified folder
for root, dirs, files in os.walk(directory):
for file in files:
_, ext = os.path.splitext(file) # Splits the filename to extract the extension
if ext: # Check whether the extension already exists
extensions.add(ext.lower()) # Adds the extension and uses lowercase
return print(extensions)
find_file_extensions(directory)