Directory.copy erase the content of the original file

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Antilo

Hello, … i’m turning crazy,
i’m trying to make a file copy as part of the creation a new character for a rpg,…
when i do :

var dir = Directory.new()
var dialogodestino = "res://dialog" + charactername + ".json"
dir.copy("res://dialog.json", dialogodestino)

the new file is created correctly, but both, file from and file destination are empty with 0 lines … any idea what i’m doing wrong?

:bust_in_silhouette: Reply From: Antilo

Ok i answer myself… the code works if writting like this

var dir = Directory.new()
var dialogodestino = "res://dialog" + charactername + ".json"
dir.copy("res://dialog.json", str(dialogodestino))

noticy that the destination must specify String as str() if the variable wants to be used