From d5469a64d230e3929c327a34a9c5a6965e6d4071 Mon Sep 17 00:00:00 2001 From: xqyz <10251866+bphd@users.noreply.github.com> Date: Sun, 12 Jan 2025 07:29:45 +0000 Subject: [PATCH] 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. --- aider/commands.py | 1 + 1 file changed, 1 insertion(+) diff --git a/aider/commands.py b/aider/commands.py index 13f267a12cc..ab5f121a84f 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -756,6 +756,7 @@ def cmd_add(self, args): if self.io.confirm_ask(f"No files matched '{word}'. Do you want to create {fname}?"): try: + fname.parent.mkdir(parents=True, exist_ok=True) fname.touch() all_matched_files.add(str(fname)) except OSError as e: