Filepath validation in Visual C

57 Views Asked by At

I have an unmanaged Win32 project in Visual studio. It is using only C language. For a function, I am getting a parameter as 'filepath'. I have to validate filepath.

A test case will be written which will check, if the filepath is existed or not. It will give filepath(valid in syntax) which is not existed and ask to save/load the file.

How to handle this? How to check if filepath is existed or not in C?

My project setting is "No Common Language Runtime Support".

And I am not supposed to change this.

1

There are 1 best solutions below

0
On

Following function will help:

int fileExists(TCHAR * file)
{
   WIN32_FIND_DATA FindFileData;
   HANDLE handle = FindFirstFile(file, &FindFileData) ;
   int found = handle != INVALID_HANDLE_VALUE;
   if(found) 
   {
       FindClose(handle);
   }
   return found;
}