Skip to content

Commit 8f67d41

Browse files
authored
Speed up list_directory tool (#851)
# Motivation <!-- Why is this change necessary? --> # Content <!-- Please include a summary of the change --> # Testing <!-- How was the change tested? --> # Please check the following before marking your PR as ready for review - [ ] I have added tests for my changes - [ ] I have updated the documentation or added new documentation as needed
1 parent a9b29fa commit 8f67d41

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/codegen/extensions/tools/list_directory.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,8 @@ def get_directory_info(dir_obj: Directory, current_depth: int) -> DirectoryInfo:
140140
"""Helper function to get directory info recursively."""
141141
# Get direct files (always include files unless at max depth)
142142
all_files = []
143-
for file in dir_obj.files(recursive=True):
144-
if file.directory == dir_obj:
145-
all_files.append(file.filepath.split("/")[-1])
143+
for file_name in dir_obj.file_names:
144+
all_files.append(file_name)
146145

147146
# Get direct subdirectories
148147
subdirs = []

src/codegen/sdk/core/directory.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,11 @@ def item_names(self, recursive: bool = False) -> list[str]:
196196
"""
197197
return self._files + self._subdirectories
198198

199+
@property
200+
def file_names(self) -> list[str]:
201+
"""Get a list of all file names in the directory."""
202+
return self._files
203+
199204
@property
200205
def tree(self) -> list[Self | TFile]:
201206
"""Get a recursive list of all files and subdirectories in the directory.

0 commit comments

Comments
 (0)