From d780520d5179609a877daf2d683d6a6150fcd4a9 Mon Sep 17 00:00:00 2001 From: blinry Date: Fri, 5 Feb 2021 16:20:52 +0100 Subject: [PATCH] When writing a file, make sure that its parent directory exists Fixes #13. --- scenes/helpers.gd | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/scenes/helpers.gd b/scenes/helpers.gd index f8e3eac..8a67d79 100644 --- a/scenes/helpers.gd +++ b/scenes/helpers.gd @@ -55,6 +55,15 @@ func read_file(path, fallback_string=null): func write_file(path, content): if debug_file_io: print("writing " + path) + + # Create the base directory of the file, if it doesn't exist. + var parts = Array(path.split("/")) + parts.pop_back() + var dirname = PoolStringArray(parts).join("/") + var dir = Directory.new() + if not dir.dir_exists(path): + dir.make_dir_recursive(dirname) + var file = File.new() file.open(path, File.WRITE) file.store_string(content)