You need to create new directories if they haven't already existed.
I also cleaned up unnecessary checks by adding typing so you won't need to call your getDataType()
which you can probably replace with typeof():
if typeof(fileName) != TYPE_STRING:
Anyway, here's the function:
static func writeToFile(data, fileDir:String, fileName:String):
var filePath = "user://%s" % fileDir
var directory = Directory.new()
if not directory.dir_exists(filePath):
directory.make_dir_recursive(filePath)
filePath = filePath.plus_file(fileName)
var file = File.new()
if file.open(filePath, File.WRITE) == OK:
file.store_line(data)
file.close()
else:
print("Error opening file")
Will even create sub-directories if not existed:
writeToFile("Hello World!", "", "hw.txt")
writeToFile("Hello Underworld!", "under/world", "hw.txt")
Regarding zipping, it's not been implemented yet in GDSript. You can probably do it with C++, but that's beyond my knowledge.