* WINDOWS function to resolve wildcards and recurse into sub directories. * The fileName vector is filled with the path and names of files to process. * * @param directory The path of the directory to be processed. * @param wildcard The wildcard to be processed (e.g. *.cpp). */
| 818 | * @param wildcard The wildcard to be processed (e.g. *.cpp). |
| 819 | */ |
| 820 | void ASConsole::getFileNames(const string& directory, const string& wildcard) |
| 821 | { |
| 822 | vector<string> subDirectory; // sub directories of directory |
| 823 | WIN32_FIND_DATA findFileData; // for FindFirstFile and FindNextFile |
| 824 | |
| 825 | // Find the first file in the directory |
| 826 | // Find will get at least "." and "..". |
| 827 | string firstFile = directory + "\\*"; |
| 828 | HANDLE hFind = FindFirstFile(firstFile.c_str(), &findFileData); |
| 829 | |
| 830 | if (hFind == INVALID_HANDLE_VALUE) |
| 831 | { |
| 832 | // Error (3) The system cannot find the path specified. |
| 833 | // Error (123) The filename, directory name, or volume label syntax is incorrect. |
| 834 | // ::FindClose(hFind); before exiting |
| 835 | displayLastError(); |
| 836 | error(_("Cannot open directory"), directory.c_str()); |
| 837 | } |
| 838 | |
| 839 | // save files and sub directories |
| 840 | do |
| 841 | { |
| 842 | // skip hidden or read only |
| 843 | if (findFileData.cFileName[0] == '.' |
| 844 | || (findFileData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) |
| 845 | || (findFileData.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) |
| 846 | continue; |
| 847 | |
| 848 | // is this a sub directory |
| 849 | if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) |
| 850 | { |
| 851 | if (!isRecursive) |
| 852 | continue; |
| 853 | // if a sub directory and recursive, save sub directory |
| 854 | string subDirectoryPath = directory + g_fileSeparator + findFileData.cFileName; |
| 855 | if (isPathExclued(subDirectoryPath)) |
| 856 | printMsg(_("Exclude %s\n"), subDirectoryPath.substr(mainDirectoryLength)); |
| 857 | else |
| 858 | subDirectory.push_back(subDirectoryPath); |
| 859 | continue; |
| 860 | } |
| 861 | |
| 862 | // save the file name |
| 863 | string filePathName = directory + g_fileSeparator + findFileData.cFileName; |
| 864 | // check exclude before wildcmp to avoid "unmatched exclude" error |
| 865 | bool isExcluded = isPathExclued(filePathName); |
| 866 | // save file name if wildcard match |
| 867 | if (wildcmp(wildcard.c_str(), findFileData.cFileName)) |
| 868 | { |
| 869 | if (isExcluded) |
| 870 | printMsg(_("Exclude %s\n"), filePathName.substr(mainDirectoryLength)); |
| 871 | else |
| 872 | fileName.push_back(filePathName); |
| 873 | } |
| 874 | } |
| 875 | while (FindNextFile(hFind, &findFileData) != 0); |
| 876 | |
| 877 | // check for processing error |