Skip to content

Commit 773059d

Browse files
committed
[Find File/Python] Fixed perf issue
1 parent a2fab03 commit 773059d

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

public/data/python.json

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,13 @@
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')",

0 commit comments

Comments
 (0)