Main Site Documentation

FEZ Spider + SD Module, check file exists


#1

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


#2

:slight_smile:

Yeah, indeed…
Try this one:


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


#3

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


#4

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