------------------------------------------------------------------------------
| 60 | |
| 61 | //------------------------------------------------------------------------------ |
| 62 | int vtkGlobFileNames::AddFileNames(const char* pattern) |
| 63 | { |
| 64 | this->SetPattern(pattern); |
| 65 | |
| 66 | vtksys::Glob glob; |
| 67 | |
| 68 | if (this->Recurse) |
| 69 | { |
| 70 | glob.RecurseOn(); |
| 71 | } |
| 72 | else |
| 73 | { |
| 74 | glob.RecurseOff(); |
| 75 | } |
| 76 | |
| 77 | if (!this->Pattern) |
| 78 | { |
| 79 | vtkErrorMacro(<< "FindFileNames: pattern string is null."); |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | std::string fullPattern = this->Pattern; |
| 85 | |
| 86 | if (this->Directory && this->Directory[0] != '\0') |
| 87 | { |
| 88 | std::vector<std::string> components; |
| 89 | vtksys::SystemTools::SplitPath(fullPattern, components); |
| 90 | // If Pattern is a relative path, prepend with Directory |
| 91 | if (components[0].empty()) |
| 92 | { |
| 93 | components.insert(components.begin(), this->Directory); |
| 94 | fullPattern = vtksys::SystemTools::JoinPath(components); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | if (!glob.FindFiles(fullPattern)) |
| 99 | { |
| 100 | vtkErrorMacro(<< "FindFileNames: Glob action failed for \"" << fullPattern << "\""); |
| 101 | |
| 102 | return 0; |
| 103 | } |
| 104 | |
| 105 | // copy the filenames from glob |
| 106 | std::vector<std::string> files = glob.GetFiles(); |
| 107 | |
| 108 | // sort them lexicographically |
| 109 | std::sort(files.begin(), files.end()); |
| 110 | |
| 111 | // add them onto the list of filenames |
| 112 | for (std::vector<std::string>::const_iterator iter = files.begin(); iter != files.end(); ++iter) |
| 113 | { |
| 114 | this->FileNames->InsertNextValue(iter->c_str()); |
| 115 | } |
| 116 | |
| 117 | return 1; |
| 118 | } |
| 119 |