Code snippet for searching a file in directory (directory can have subdirectories in it)
-
Hi, I need to search for a file in a specific directory. This directory would also have subdirectories in it. Can I have a API / code snippet for this. Thanks in advance.
-
Hi, I need to search for a file in a specific directory. This directory would also have subdirectories in it. Can I have a API / code snippet for this. Thanks in advance.
FindFirstFile、FindNextFile
-
Hi, I need to search for a file in a specific directory. This directory would also have subdirectories in it. Can I have a API / code snippet for this. Thanks in advance.
In addition to FindFirstFile, you could use FileExists to search each directory for a match. If you intend to search subdirectories, you still need to to identify them. #include //for FileExists bool FileExists(char * const strFilename) { struct stat stFileInfo; bool blnReturn; int intStat; // Attempt to get the file attributes intStat = stat(strFilename,&stFileInfo); if(intStat == 0) { // We were able to get the file attributes // so the file obviously exists. blnReturn = true; } else { // We were not able to get the file attributes. // This may mean that we don't have permission to // access the folder which contains this file. If you // need to do that level of checking, lookup the // return values of stat which will give you // more details on why stat failed. blnReturn = false; } return(blnReturn); }