Cannot Rename a file on the C directory

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

So, I’m trying to implement a simple renaming of a file, but every time I try to do it it simply fails with the Error code 1 → Generic Error.


   var dir : Directory =
    	print("OLD: ",old_path)
    	print("NEW: ",new_path)
    	if dir.rename(old_path, new_path) == OK:


 OLD: C:/Users/hinte/AppData/Roaming/Godot/app_userdata/Veles/music/Slow Jamz.mp3
NEW: C:/Users/hinte/AppData/Roaming/Godot/app_userdata/Veles/music/Slow Jams.mp3

Btw I’m on Windows and I’ve also checked if the old path exists, which it does.

Any Help would be appreciated.

can you identify if the file you’re trying to modify is being locked by a process?

MEDBVLL | 2022-07-28 16:15

That code should work. I assume there must be something “non-standard” about one or both of the files in question (inaccessible, permission issues, locked by another process, …).

Related, can you successfully move from/to the same file names via a CMD terminal? If not, what error do you see there?

jgodfrey | 2022-07-28 17:45

Yeah thanks I’m just dumb. I read the header of the File I want to rename prior and forget to close the File, so obviously the rename gets blocked when it’s currently in use. Thanks for quick Answer :slight_smile:

LyffLyff | 2022-07-28 21:32

:bust_in_silhouette: Reply From: LyffLyff

I opened the File prior to read it’s header and forgot to call the .close() function on the Reference of the File. So the File was currently in use, obviously preventing the rename.