Created
July 2, 2024 16:40
-
-
Save gmotzespina/2b9a17070b0b11201422d33f50956ec6 to your computer and use it in GitHub Desktop.
File System Example
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 find_files(directory, pattern): | |
| for item in os.listdir(directory): | |
| full_path = os.path.join(directory, item) | |
| if os.path.isfile(full_path) and pattern in item: | |
| print(full_path) | |
| elif os.path.isdir(full_path): | |
| find_files(full_path, pattern) # Recurse into subdirectory | |
| find_files('/path/to/your/directory', '.txt') # Find all .txt files |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment