/ SDR FindInDir: returns the number of retrieved files. */ /
| 1036 | /* SDR FindInDir: returns the number of retrieved files. */ |
| 1037 | /***********************************************************************/ |
| 1038 | int TDBSDR::FindInDir(PGLOBAL g) |
| 1039 | { |
| 1040 | int n = 0; |
| 1041 | size_t m = strlen(Direc); |
| 1042 | |
| 1043 | // Start searching files in the target directory. |
| 1044 | #if defined(_WIN32) |
| 1045 | int rc; |
| 1046 | HANDLE h; |
| 1047 | |
| 1048 | #if defined(PATHMATCHSPEC) |
| 1049 | if (!*Drive) |
| 1050 | Path(g); |
| 1051 | |
| 1052 | _makepath(Fpath, Drive, Direc, "*", "*"); |
| 1053 | |
| 1054 | h = FindFirstFile(Fpath, &FileData); |
| 1055 | |
| 1056 | if (h == INVALID_HANDLE_VALUE) { |
| 1057 | rc = GetLastError(); |
| 1058 | |
| 1059 | if (rc != ERROR_FILE_NOT_FOUND) { |
| 1060 | char buf[512]; |
| 1061 | |
| 1062 | FormatMessage(FORMAT_MESSAGE_FLAGS, |
| 1063 | NULL, GetLastError(), 0, (LPTSTR)&buf, sizeof(buf), NULL); |
| 1064 | snprintf(g->Message, sizeof(g->Message), MSG(BAD_FILE_HANDLE), buf); |
| 1065 | return -1; |
| 1066 | } // endif rc |
| 1067 | |
| 1068 | return 0; |
| 1069 | } // endif h |
| 1070 | |
| 1071 | while (true) { |
| 1072 | if ((FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && |
| 1073 | *FileData.cFileName != '.') { |
| 1074 | // Look in the name sub-directory |
| 1075 | strcat(strcat(Direc, FileData.cFileName), "/"); |
| 1076 | n += FindInDir(g); |
| 1077 | Direc[m] = '\0'; // Restore path |
| 1078 | } else if (PathMatchSpec(FileData.cFileName, Fpath)) |
| 1079 | n++; |
| 1080 | |
| 1081 | if (!FindNextFile(h, &FileData)) { |
| 1082 | rc = GetLastError(); |
| 1083 | |
| 1084 | if (rc != ERROR_NO_MORE_FILES) { |
| 1085 | snprintf(g->Message, sizeof(g->Message), MSG(NEXT_FILE_ERROR), rc); |
| 1086 | FindClose(h); |
| 1087 | return -1; |
| 1088 | } // endif rc |
| 1089 | |
| 1090 | break; |
| 1091 | } // endif Next |
| 1092 | |
| 1093 | } // endwhile |
| 1094 | #else // !PATHMATCHSPEC |
| 1095 | h = FindFirstFile(Path(g), &FileData); |
no test coverage detected