#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers //#include "afx.h" #include #include "SFind.h" //-------------------------------------------------------------------- SFind::SFind(char *SearchMask, char *SearchPath) { hFind = NULL; hFind2 = NULL; strcpy(SSearchPath, SearchPath); //--make sure ends in backslash if (strlen(SSearchPath)) if (SSearchPath[strlen(SSearchPath) - 1] != '\\') strcat(SSearchPath, "\\"); strcpy(ToSearch, SSearchPath); strcat(ToSearch, SearchMask); strcpy(SSearchPattern, SearchMask); } //-------------------------------------------------------------------- SFind::~SFind() { if (hFind) { FindClose(hFind); hFind = NULL; } if (hFind2) { FindClose(hFind2); hFind2 = NULL; } } //-------------------------------------------------------------------- bool SFind::Found(void) { ZeroMemory(&FindFileData, sizeof(WIN32_FIND_DATA)); //----first?----- if (!hFind) { hFind = FindFirstFile(ToSearch, &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { hFind = NULL; // nothing return(false); } } else { // find next if (!FindNextFile(hFind, &FindFileData)) return(false); // finished } //-----got something?---- if (!strlen(FindFileData.cFileName)) return(false); //-----we do not want .. or . --------- while (strcmp(FindFileData.cFileName, ".") == 0 || strcmp(FindFileData.cFileName, "..") == 0) { if (!Found()) // recall return(false); } //-------found------------- return(true); } //-------------------------------------------------------------------- char *SFind::FileName(void) { strcpy(TempReturnFullFilename, SSearchPath); strcat(TempReturnFullFilename, FindFileData.cFileName); return(TempReturnFullFilename); } //-------------------------------------------------------------------- char *SFind::JustFileName(void) { return(FindFileData.cFileName); } //-------------------------------------------------------------------- bool SFind::IsFolder(void) { if (hFind && FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) return(true); else return(false); }