File tree Expand file tree Collapse file tree 1 file changed +6
-10
lines changed Expand file tree Collapse file tree 1 file changed +6
-10
lines changed Original file line number Diff line number Diff line change 131131 " import os" ,
132132 " " ,
133133 " def find_files(directory, file_type):" ,
134- " file_type = file_type.lower() # Convert file_type to lowercase " ,
135- " found_files = []" ,
134+ " file_type = file_type.lower()" ,
135+ " found_files = []" ,
136136 " " ,
137- " for root, _, files in os.walk(directory):" ,
138- " for file in files:" ,
139- " file_ext = os.path.splitext(file)[1].lower()" ,
140- " if file_ext == file_type:" ,
141- " full_path = os.path.join(root, file)" ,
142- " found_files.append(full_path)" ,
143- " " ,
144- " return found_files" ,
137+ " for entry in os.scandir(directory):" ,
138+ " if entry.is_file() and entry.name.lower().endswith(file_type):" ,
139+ " found_files.append(entry.name)" ,
140+ " return found_files" ,
145141 " " ,
146142 " # Example Usage:" ,
147143 " pdf_files = find_files('/path/to/your/directory', '.pdf')" ,
You can’t perform that action at this time.
0 commit comments