|
187 | 187 | "import os",
|
188 | 188 | "",
|
189 | 189 | "def find_files(directory, file_type):",
|
190 | | - " file_type = file_type.lower() # Convert file_type to lowercase", |
191 | | - " found_files = []", |
| 190 | + " file_type = file_type.lower()", |
| 191 | + " found_files = []", |
192 | 192 | "",
|
193 | | - " for root, _, files in os.walk(directory):", |
194 | | - " for file in files:", |
195 | | - " file_ext = os.path.splitext(file)[1].lower()", |
196 | | - " if file_ext == file_type:", |
197 | | - " full_path = os.path.join(root, file)", |
198 | | - " found_files.append(full_path)", |
199 | | - "", |
200 | | - " return found_files", |
| 193 | + " for entry in os.scandir(directory):", |
| 194 | + " if entry.is_file() and entry.name.lower().endswith(file_type):", |
| 195 | + " found_files.append(entry.name)", |
| 196 | + " return found_files", |
201 | 197 | "",
|
202 | 198 | "# Example Usage:",
|
203 | 199 | "pdf_files = find_files('/path/to/your/directory', '.pdf')",
|
|
0 commit comments