Created
November 28, 2024 21:57
-
-
Save janusson/45a18e7498ef4f8d1a1b84dd16263013 to your computer and use it in GitHub Desktop.
Retrieves the relative paths of all CSV files in the specified directory.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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