0 votes

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://godotengine.org/qa/17959/file-not-exist-on-android

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

in Engine by (12 points)

1 Answer

+1 vote
by (427 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.