Save a file from RES:// to USER:// on Android

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

Good day.

I am trying to save a database file from res:// folder to user:// folder using the code below:

if !o.file_exists("user://test-new.db"):
	print("does not exists")
	
	# Delete old test version
	if o.file_exists("user://test-old.db"):
		print("deleting old")
		dir.remove("user://test-old.db")
	else:
		print("no old file")
	
        # Copy the file from RES/dbase to USER
	print("copying files")
	dir.copy("res://assets/dbase/test-new.db","user://test-new.db")
	print("done")

It works fine when I run it on PC but I am getting the following error in logcat when running in android

05-27 22:47:38.447 23258 23272 I godot : does not exists

05-27 22:47:38.447 23258 23272 I godot : no old file

05-27 22:47:38.447 23258 23272 I godot : copying files

05-27 22:47:38.449 23258 23272 E godot : ERROR: Condition ’ err ’ is true. returned: err

05-27 22:47:38.449 23258 23272 E godot : At: core/os/dir_access.cpp:305:copy() - Condition ’ err ’ is true. returned: err

05-27 22:47:38.449 23258 23272 I godot : done


I am under the impression that either I cannot write to the destination file, or my source file is not accessible. I was able to write a file on user:// by using file.open so I know I have access to user directory.

I hope someone could shed a light on how to better do this procedure.

BTW, If anyone is curious why I am copying a database to a user folder, I am basically using gdsqlite to access the content of the database to my application. Gdsqlite does require the database to be in user:// folder. It does works fine on PC but not on android devices on which I intend to use it. It is a 5-10mb database and I want it to be stored locally instead of the apps accessing the internet.

Cheers


Edit: Please close, I found the answer at https://forum.godotengine.org/17959/file-not-exist-on-android

I added *.db in "Export\Resource\Filter to Export non resource file and it worked!

:bust_in_silhouette: Reply From: hungrymonkey

bugged in godot 3