Skip to content

Instantly share code, notes, and snippets.

@janusson
Created November 28, 2024 21:57
Show Gist options
  • Select an option

  • Save janusson/45a18e7498ef4f8d1a1b84dd16263013 to your computer and use it in GitHub Desktop.

Select an option

Save janusson/45a18e7498ef4f8d1a1b84dd16263013 to your computer and use it in GitHub Desktop.
Retrieves the relative paths of all CSV files in the specified directory.
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.
"""
csv_files = []
try:
for root, dirs, files, in os.walk(directory_path):
for file in files:
if file.lower().endswith('.csv'):
csv_files.append(os.path.join(root, file))
except Exception as e:
print(f"An error occurred: {e}")
return csv_files
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment