23 #include <sys/types.h>
63 char path_name[strlen(path)+1];
64 strcpy(path_name, path);
94 char path_name[strlen(path)+1];
95 strcpy(path_name, path);
129 bool has_glob(
false);
132 if (path == 0) {
return flist; }
133 if (glob_str[0] !=
'\0') { has_glob =
true; }
135 DIR* dir_ptr(::opendir(path));
136 if (dir_ptr == 0) {
return flist; }
138 while ((ent = ::readdir(dir_ptr)) != 0)
143 const char* globc(glob_str);
144 std::string fname(ent->d_name);
145 for (
size_t i(0); i < fname.size() && globc !=
'\0'; ++i, ++globc)
150 if (globc[1] ==
'\0') {
break; }
152 if (globc[1] ==
'*' || globc[1] ==
'+') { --i;
continue; }
156 size_t pos(fname.find(*globc, i));
157 if (pos == std::string::npos) { match =
false;
break; }
161 else if (*globc ==
'+')
164 if (globc[1] ==
'\0' && !(i + 1 < fname.size())) {
break; }
166 if (globc[1] ==
'*' || globc[1] ==
'+') { --i;
continue; }
170 size_t pos(fname.find(*globc, i + 1));
171 if (pos == std::string::npos) { match =
false;
break; }
177 if (fname[i] != *globc) { match =
false; }
182 if (i + 1 == fname.size() &&
183 globc[1] !=
'\0' && globc[1] !=
'*') { match =
false; }
186 if (match) { flist.push_back(ent->d_name); }
194 #endif // COIL_FILE_H
std::vector< std::string > vstring
Definition: stringutil.h:37
std::string dirname(char *path)
Get a directory part than a file pass.
Definition: File.h:61
coil::vstring filelist(const char *path, const char *glob_str="")
Get file list.
Definition: File.h:125
std::string basename(const char *path)
Get a file name part than a file pass.
Definition: File.h:92