How do you check if a file / resource exist?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Tybobobo
:warning: Old Version Published before Godot 3 was released.

Is there a simple (universal) way to check if a file exists?

:bust_in_silhouette: Reply From: kubecz3k
var file2Check =
var doFileExists = file2Check.file_exists(PATH_2_FILE):

You can also use Directory class:

var directory =;
var doFileExists = directory.file_exists(PATH_2_FILE)

PATH_2_FILE should be in “res://data/file.extension” format

Perfect! Thank you :slight_smile:
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 and

Bojidar Marinov | 2016-02-27 15:52

For resources, use ResourceLoader.exists("res://sprite.tscn")

Poobslag | 2020-04-03 22:38

:bust_in_silhouette: Reply From: salihkallai

to check whether a directory exists or not, use

var directory =;
var doFileExists = directory.dir_exists(PATH_2_DIRECTORY)

note: GODOT 3.0+

salihkallai | 2019-03-06 08:51