0 votes

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.

asked Apr 22 in Engine by Batticus (12 points)

1 Answer

0 votes

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.

answered May 6 by akoutsoulelos (14 points)

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.

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?

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 : )

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 How to use this Q&A? before posting your first questions.