mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-18 06:24:20 +01:00
create file dir if it doesnt exist during write_to_file
This commit is contained in:
@@ -29,13 +29,14 @@ def read_file(filename):
|
|||||||
|
|
||||||
|
|
||||||
def write_to_file(filename, text):
|
def write_to_file(filename, text):
|
||||||
try:
|
filepath = safe_join(working_directory, filename)
|
||||||
filepath = safe_join(working_directory, filename)
|
directory = os.path.dirname(filepath)
|
||||||
with open(filepath, "w") as f:
|
if not os.path.exists(directory):
|
||||||
f.write(text)
|
os.makedirs(directory)
|
||||||
return "File written to successfully."
|
with open(filepath, "w") as f:
|
||||||
except Exception as e:
|
f.write(text)
|
||||||
return "Error: " + str(e)
|
return "File written to successfully."
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def append_to_file(filename, text):
|
def append_to_file(filename, text):
|
||||||
|
|||||||
Reference in New Issue
Block a user