The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+1 vote

Im trying to read the extension of a file, is there a function like, get_extension(), or something like that?

in Engine by (37 points)

3 Answers

0 votes

No, but if you're using a Directory to get files, you can get the file extension from the name of the file since it's at the end of the name.

by (8,550 points)
–1 vote

once you get the full path to your file using directory, just use get_extension()
example below

func dircontents(path):
var dir =
if == OK:
var file
name = dir.getnext()
while file
name != "":
if dir.currentisdir():
print("Found directory: " + filename)
print("Found file: " + file
filename = dir.getnext()
print("An error occurred when trying to access the path.")

func onButtonpressed():

by (28 points)

under scores have been removed in my above post. so please use correct functions

+1 vote

I am a bit late to the party - but for anyone stumbling across this via search engine: Godot Strings provide the exact wished functionality by now:

by (45 points)
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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.