Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Tybobobo | |
Old Version | Published before Godot 3 was released. |
Is there a simple (universal) way to check if a file exists?
Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Tybobobo | |
Old Version | Published before Godot 3 was released. |
Is there a simple (universal) way to check if a file exists?
Reply From: | kubecz3k |
var file2Check = File.new()
var doFileExists = file2Check.file_exists(PATH_2_FILE):
You can also use Directory class:
var directory = Directory.new();
var doFileExists = directory.file_exists(PATH_2_FILE)
PATH_2_FILE
should be in “res://data/file.extension” format
Perfect! Thank you
I was using ConfigFile - but that does not seem to have anything similar (yet)
Tybobobo | 2016-02-27 15:50
Note that you can make it a one-liner with Directory.new().file_exists(PATH_2_FILE)
and File.new().file_exists(PATH_2_FILE)
Bojidar Marinov | 2016-02-27 15:52
For resources, use ResourceLoader.exists("res://sprite.tscn")
Poobslag | 2020-04-03 22:38
Reply From: | salihkallai |
to check whether a directory exists or not, use
var directory = Directory.new();
var doFileExists = directory.dir_exists(PATH_2_DIRECTORY)
note: GODOT 3.0+
salihkallai | 2019-03-06 08:51