Skip to content

Instantly share code, notes, and snippets.

@janusson
Last active May 25, 2025 01:38
Show Gist options
  • Save janusson/1c14bbbb12bd2b72f4c2a9334d248292 to your computer and use it in GitHub Desktop.
Save janusson/1c14bbbb12bd2b72f4c2a9334d248292 to your computer and use it in GitHub Desktop.
This function navigates through the specified directory and its subdirectories to find all files that end with .csv. It then returns a list containing the relative paths of these files.
import os
def get_csv_file_paths(directory_path) -> list:
"""
Retrieves the relative paths of all CSV files in the specified directory.
Args:
directory_path (str): Path to the directory containing CSV files.
Returns:
list: List of relative file paths for CSV files.
"""
return [os.path.join(root, file) for root, _, files in os.walk(directory_path) for file in files if file.lower().endswith('.csv')]
@janusson
Copy link
Author

janusson commented Dec 8, 2024

Get CSV File Paths Description

This function navigates through the specified directory and its subdirectories to find all files that end with .csv. It then returns a list containing the relative paths of these files.

get_csv_file_paths.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment