mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 14:55:00 +00:00
aider: Refactored expand_subdir
to use pathlib
for recursively finding all files in the given directory.
# Aider chat conversation: USER: make `expand_subdir` use pathlib ASSISTANT: To modify the `expand_subdir` function to use `pathlib`, we need to modify the `aider/commands.py` file. Here are the changes: ```python aider/commands.py <<<<<<< ORIGINAL def expand_subdir(file_path): for root, dirs, files in os.walk(file_path): for fname in files: yield fname ======= from pathlib import Path def expand_subdir(file_path): for file in Path(file_path).rglob('*'): if file.is_file(): yield str(file) >>>>>>> UPDATED ``` This change replaces the `os.walk` function with the `Path.rglob` method from `pathlib`, which recursively finds all files in the given directory. The `is_file` method is used to ensure we only yield files, not directories. The `str` function is used to convert the `Path` object to a string.
This commit is contained in:
parent
f48aeac88b
commit
65c12a73f6
1 changed files with 5 additions and 3 deletions
|
@ -396,7 +396,9 @@ class Commands:
|
|||
self.io.tool_output(f"{cmd} No description available.")
|
||||
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
def expand_subdir(file_path):
|
||||
for root, dirs, files in os.walk(file_path):
|
||||
for fname in files:
|
||||
yield fname
|
||||
for file in Path(file_path).rglob('*'):
|
||||
if file.is_file():
|
||||
yield str(file)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue