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 12991299 " import os" ,
13001300 " " ,
13011301 " def find_files(directory, file_type):" ,
1302- " file_type = file_type.lower() # Convert file_type to lowercase " ,
1303- " found_files = []" ,
1302+ " file_type = file_type.lower()" ,
1303+ " found_files = []" ,
13041304 " " ,
1305- " for root, _, files in os.walk(directory):" ,
1306- " for file in files:" ,
1307- " file_ext = os.path.splitext(file)[1].lower()" ,
1308- " if file_ext == file_type:" ,
1309- " full_path = os.path.join(root, file)" ,
1310- " found_files.append(full_path)" ,
1311- " " ,
1312- " return found_files" ,
1305+ " for entry in os.scandir(directory):" ,
1306+ " if entry.is_file() and entry.name.lower().endswith(file_type):" ,
1307+ " found_files.append(entry.name)" ,
1308+ " return found_files" ,
13131309 " " ,
13141310 " # Example Usage:" ,
13151311 " pdf_files = find_files('/path/to/your/directory', '.pdf')" ,
You can’t perform that action at this time.
0 commit comments