Sometimes might have used following code snippet to check whether a file existing or not.
WIN32_FIND_DATA fdt;
HANDLE hFile = ::FindFirstFile( _T("C:\\Downloads"),&fdt);
The above code may succeed if you give a valid local path in your HDD.
Sometimes you may need to check a share in network existing or not. So What would you do? You may write something as follows
//Try with network file path
WIN32_FIND_DATA fdt;
HANDLE hFile = ::FindFirstFile( _T("\\\\writer\\Downloads"),&fdt);
What’s wrong with above code? The code would fail and return error code 0×35(53) (Use GetLastError()).(Error Message: “The network path was not found”)
As per the documentation, giving path of a network share is a bit different.
On network shares, you can use an lpFileName in the form of the following: “\\server\service\*”. However, you cannot use an lpFileName that points to the share itself; for example, “\\server\service” is not valid.
So the following code will work fine for you
WIN32_FIND_DATA fdt;
HANDLE hFile = ::FindFirstFile( _T("\\\\writer\\Downloads\\*"),&fdt);
We have a simple and smart way to check the existance of a file or path with a simple API. As you see below.
//Try with Shell API
if( PathFileExists(_T("\\\\writer\\Downloads") ) )
{
MessageBox( _T( "Succeed to find file" ));
};