Checking if a File Exists

Hey all,

I was wondering if there is a simple way to check if a file of a certain type (specifically, FLV) exists within a folder, using AS3. What I want to do is something along these lines…


if(an FLV file exists within a certain folder){
      //Do something!
}

Any help would be much appreciated. Thanks in advance!

tbeanz

Sorry, this isn’t possible without help from a server-side script running on your web server. (PHP / ASP / etc…)

Not sure about AS3 but this AS2 code works - just try loading the file (even if Flash can’t actually use it) and check the onLoad handler:

fileExists = new LoadVars();
fileExists.onLoad = function(success) {
	//success is true if the file exists, false if it doesnt
	if (success) {
		//the file exists
		trace("the file " + fileName + " exists");
	} else {
		trace("the file " + fileName + " doesn't exist");
	}
};
fileName = "http://www.mysite.com/video.flv";
fileExists.load(fileName);

That’d work if he wanted to check for a specific file name, but I think he wanted to look for any and all FLV files, which is a little harder.

Thanks for your help, guys. I’ll definitely look into the server-side script. I remember you can do file checking easily with PHP, so I’ll give that a try.