import os from collections import defaultdict # Set the folder path folder_path = "P:\\" # Change this to your target directory # Define common video file extensions video_extensions = {"mp4", "mkv", "avi", "mov", "wmv", "flv", "webm", "mpeg", "mpg"} # Dictionary to store files grouped by extension videos_by_type = defaultdict(list) # Iterate over files in the folder for file in os.listdir(folder_path): if os.path.isfile(os.path.join(folder_path, file)): ext = file.split(".")[-1].lower() if ext in video_extensions: videos_by_type[ext].append(file) # Print the results for ext, files in videos_by_type.items(): print(f".{ext} files:") for file in files: print(f" - {file}")