mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-18 13:55:17 +02:00
create parent folder in Editor.create_file
This commit is contained in:
parent
f03f2c43a3
commit
58907d0dbb
1 changed files with 3 additions and 2 deletions
|
|
@ -352,13 +352,14 @@ class Editor(BaseModel):
|
|||
"""Creates and opens a new file with the given name.
|
||||
|
||||
Args:
|
||||
filename: str: The name of the file to create.
|
||||
filename: str: The name of the file to create. If the parent directory does not exist, it will be created.
|
||||
"""
|
||||
filename = self._try_fix_path(filename)
|
||||
|
||||
if filename.exists():
|
||||
raise FileExistsError(f"File '{filename}' already exists.")
|
||||
|
||||
if not filename.parent.exists():
|
||||
os.makedirs(filename.parent, exist_ok=True)
|
||||
with filename.open("w") as file:
|
||||
file.write("\n")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue