Godot Version
v4.4.1.stable.mono.official [49a5bc7b6]
Question
I am creating a horror game at the moment, and I thought it would be extra interesting if it could know your name and latest download. I’ve already got the name part working, but I’m unsure how to approach getting a file’s name.
EDIT: My code so far:
func get_user_name(path: String = OS.get_system_dir(OS.SYSTEM_DIR_DESKTOP)) -> String:
path = path.replacen("-", "_")
path = path.replacen("C:/Users/", "")
path = path.replacen("/Desktop", "")
path = path.replacen("/", "_")
path = path.capitalize()
return path
func get_last_download(path: String = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS)) -> String:
# ???
return ""
EDIT 2: I only want to get the title of the file, not the contents.
I got it to work!
func get_user_name(path: String = OS.get_system_dir(OS.SYSTEM_DIR_DESKTOP)) -> String:
path = path.replacen("-", "_")
path = path.replacen("C:/Users/", "")
path = path.replacen("/Desktop", "")
path = path.replacen("/", "_")
path = path.capitalize()
return path
func get_last_download(path: String = OS.get_system_dir(OS.SYSTEM_DIR_DOWNLOADS)) -> String:
var DownloadsFolder: PackedStringArray = DirAccess.get_files_at(path)
var newestTime: int = 0
var newestFile: FileAccess
for s in DownloadsFolder:
var file: FileAccess = FileAccess.open("/".join([path, s]), FileAccess.READ)
var fileTime: int = file.get_modified_time("/".join([path, s]))
if fileTime > newestTime:
newestTime = fileTime
newestFile = file
var fileName = newestFile.get_path()
fileName = fileName.replacen(path, "")
fileName = fileName.replacen("/", "")
return fileName
These functions only work on Windows, though.
system
Closed
January 14, 2026, 9:03pm
3
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.