mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 09:14:59 +00:00
Handle new path creation
To handle cases where a path, a file, or both need to be created, you can enhance the `fname.touch()` code as follows: ```python try: # Create parent directories if they don't exist fname.parent.mkdir(parents=True, exist_ok=True) # Create the file fname.touch() all_matched_files.add(str(fname)) self.io.tool_output(f"Created file: {fname}") except OSError as e: self.io.tool_error(f"Error creating file {fname}: {e}") ``` This code ensures that any necessary parent directories are created before attempting to create the file itself.
This commit is contained in:
parent
ac26fc6d5f
commit
d5469a64d2
1 changed files with 1 additions and 0 deletions
|
@ -756,6 +756,7 @@ class Commands:
|
||||||
|
|
||||||
if self.io.confirm_ask(f"No files matched '{word}'. Do you want to create {fname}?"):
|
if self.io.confirm_ask(f"No files matched '{word}'. Do you want to create {fname}?"):
|
||||||
try:
|
try:
|
||||||
|
fname.parent.mkdir(parents=True, exist_ok=True)
|
||||||
fname.touch()
|
fname.touch()
|
||||||
all_matched_files.add(str(fname))
|
all_matched_files.add(str(fname))
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue