Checking if a file exists without knowing the extension?
#2
You should use the Dir.glob method that returns a list of found files depending on a certain pattern.

If you really don't know the extension :
Code:
if Dir.glob("Audio/SE/" + setting + ".*").length > 0
  # Something happens
end

or with a list of extensions names :
define a constant :
Code:
AUDIO_EXT = ".{ogg,wav,mp3,mid,wma}"
then just use :
Code:
if Dir.glob("Audio/SE/" + setting + AUDIO_EXT).length > 0
  # Something happens
end
Some scripts :
Working on :
Reply }


Messages In This Thread
RE: Checking if a file exists without knowing the extension? - by MGC - 05-29-2011, 10:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
   Map name as save file name Whisper 9 10,195 05-01-2020, 05:35 PM
Last Post: Whisper
   Script Request - Variables Specific Save File JayRay 2 5,109 04-28-2014, 05:15 AM
Last Post: JayRay
   checking event coordinates? shintashi 4 7,570 05-28-2010, 03:34 PM
Last Post: Jaberwocky
   Can I execute a txt file from a script? deValdr 8 10,974 04-18-2010, 07:34 PM
Last Post: deValdr



Users browsing this thread: 2 Guest(s)