23 #include <sys/types.h> 28 #include <coil/stringutil.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; }
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
DIR * opendir(const char *name)
Open a directory stream.
Structure for directory entry.
std::vector< std::string > vstring
coil::vstring filelist(const char *path, const char *glob_str="")
Get file list.
dirent * readdir(DIR *dir)
Get a directory entry pointer.
const char * basename(const char *path)
Get a file name part than a file pass.
int closedir(DIR *dir)
Close a directory stream.
Structure for directory stream.
Common Object Interface Layer.
const char * dirname(const char *path)