Unable to remove file in custom "user://" directory

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

I have a file that needs to be deleted to clear it, but it simply does not get deleted. The error result I get is ‘1’ (Generic Error).

The ‘commented out’ lines are things I’ve tried, but none of them worked either.

func delete_gj_dat() -> void:
    var dir := Directory.new()        

    dir.open(OS.get_user_data_dir()) #<- Commented Out
    dir.open("user://") #<- Commented Out
    dir.remove("gj.dat") #<- Commented Out

    dir.remove("user://gj.dat")

I’ve stepped through the code, and it definitely reaches this code. I have the same issue with another file in my project.

Apologies if it’s something obvious, or something I didn’t read.

:bust_in_silhouette: Reply From: akoutsoulelos

Where exactly is gj.dat? Assuming it is directly under the user folder and not in any subfolder:

var dir = Directory.new()
dir.open("user://")
dir.remove("gj.dat")

or

var dir = Directory.new()
dir.remove("user://gj.dat")

should do the trick. Check also what dir.open() function returns, as the problem may lay there.

Hey there, thank you for the reply. I was beginning to think my question got buried.

The gj.dat file would be found in:

C:\Users\USERNAME\AppData\Roaming\FatBat\GeoBash\gj.dat

Which is directly in the user directory. The custom user directory is:

FatBat\GeoBash

Both ‘Directory.open()’ and ‘Directory.remove()’ return an Error. open() returns ‘0’, which is okay. However, remove() returns ‘1’, which the docs list as:

FAILED = 1
Generic error.

I also tried the code you suggested, but the file still does not delete. I’m going to look through the code, just to make sure I’m not doing something stupid. Otherwise I have no clue as to what’s going on here.

Thanks again.

Batticus | 2020-05-10 11:36

Godot default directory for user data in Windows is

%AppData%\Godot\app_userdata\APPLICATION_NAME\

so your user data sholud be located in

C:\Users\USERNAME\AppData\Roaming\Godot\app_userdata\FatBat\

Have you changed it to the custom

C:\Users\USERNAME\AppData\Roaming\FatBat\

through the applicatiopn properties in editor or are you trying to locate the file manually?

akoutsoulelos | 2020-05-11 06:01

Apologies for the late response, been busy with work.

First off, to answer your question, I have changed the user directory to

C:\Users\USERNAME\AppData\Roaming\FatBat\

That works fine, as the files are successfully generated in that location, and I can save/load settings from the settings file stored there.

That being said, I manually deleted gj.dat, and let the application re-generate the file, now it works as intended. I haven’t had time to do anymore work on the project, so I’m not sure if there is a deeper issue here or not, or if it will re-occur, but for now it seems to be working fine.

Once I get more time to check things out, I’ll have to run some rigorous tests to make sure.

Thank you so much for your time and effort : )

Batticus | 2020-05-26 16:53