//Check whether a file exist
//Portable to linux
#include <sys/stat.h>
#include <string>
using namespace std;
bool FileExists(string strFilename)
{
struct stat stFileInfo;
bool blnReturn= false;
int intStat=-1;
// Attempt to get the file attributes
intStat = stat(strFilename.c_str(),&stFileInfo);
if(intStat == 0)
{
// We were able to get the file attributes
blnReturn = true;
}
else
{
// We were not able to get the file attributes.
blnReturn = false;
}
return blnReturn;
}
No comments:
Post a Comment