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 187187 " import os" ,
188188 " " ,
189189 " 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 = []" ,
192192 " " ,
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" ,
201197 " " ,
202198 " # Example Usage:" ,
203199 " pdf_files = find_files('/path/to/your/directory', '.pdf')" ,
You can’t perform that action at this time.
0 commit comments