access to path
-
How can i know that a certain path is valid??? In a browse button the user select a path and i want to know if it is a valid path. i tried to use _access(char* path ,in mode) but i have a problem with it: 1) I don't know what the mode should be 2) When no path was selected (char* ="") the functoin return -1 meaning i's not valid and i don't want that. Thanks
-
How can i know that a certain path is valid??? In a browse button the user select a path and i want to know if it is a valid path. i tried to use _access(char* path ,in mode) but i have a problem with it: 1) I don't know what the mode should be 2) When no path was selected (char* ="") the functoin return -1 meaning i's not valid and i don't want that. Thanks
I use the Shell Lightweight Utility APIs for this kind of stuff. You need to include "Shlwapi.h" and build with "Shlwapi.lib". The API is very easy to use. For your question, BOOL PathFileExists( LPCTSTR pszPath ); You can find this in MSDN->Platform SDK->User Interface Services->Windows Shell-> Shell Reference->Shell Lightweight Utility APIs Hope this helps!
-
How can i know that a certain path is valid??? In a browse button the user select a path and i want to know if it is a valid path. i tried to use _access(char* path ,in mode) but i have a problem with it: 1) I don't know what the mode should be 2) When no path was selected (char* ="") the functoin return -1 meaning i's not valid and i don't want that. Thanks
The other alternative is the API function GetFileAttributes(), which, despite it's name, works with directories as well. It returns -1 if the file/directory does not exist. So:
if (GetFileAttributes(path) == -1)
{
AfxMessageBox(_T("Invalid Path!"));
}
else
{
// Do stuff...
}Hope this helps. ------------------------ Derek Waters derek@lj-oz.com