FEZ Spider + SD Module, check file exists

Hi,

Just a quick question asking if there is a more elegant way to detect if a file exists on an SD card.


        bool FileExists(string filePath)
        {
            bool exists = false;
            try 
	        {
                FileStream dummy=storageDev.OpenRead(filePath);
                exists=true;
	        }
	        catch (IOException e)
	        {
                if (e.ErrorCode == IOException.IOExceptionErrorCode.FileNotFound)
                {
                    exists = false;
                }
                else
                {
                    FatalError(e.Message);
                }
	        }
            return exists;
        }

Cheers,

Jas

:slight_smile:

Yeah, indeed…
Try this one:


//usings:
using System.IO;
//your code in some method:
File.Exists("pathtoyourfilegoeshere")

Thanks,

I tried this and it always returns false whether the file exists or not. Going to stick with the complicated but works one for now :wink:

Jas

Did you hand in the correct filepath?
Maybe you used it wrong…
(Just to make sure, no offense :slight_smile: )