23 #include <sys/types.h> 28 #include <coil/stringutil.h> 58 char path_name[strlen(path)+1];
59 strcpy(path_name, path);
89 char path_name[strlen(path)+1];
90 strcpy(path_name, path);
124 bool has_glob(
false);
127 if (path == 0) {
return flist; }
128 if (glob_str[0] !=
'\0') { has_glob =
true; }
131 if (dir_ptr == 0) {
return flist; }
133 while ((ent = ::
readdir(dir_ptr)) != 0)
138 const char* globc(glob_str);
139 std::string fname(ent->
d_name);
140 for (
size_t i(0); i < fname.size() && globc !=
'\0'; ++i, ++globc)
145 if (globc[1] ==
'\0') {
break; }
147 if (globc[1] ==
'*' || globc[1] ==
'+') { --i;
continue; }
151 size_t pos(fname.find(*globc, i));
152 if (pos == std::string::npos) { match =
false;
break; }
156 else if (*globc ==
'+')
159 if (globc[1] ==
'\0' && !(i + 1 < fname.size())) {
break; }
161 if (globc[1] ==
'*' || globc[1] ==
'+') { --i;
continue; }
165 size_t pos(fname.find(*globc, i + 1));
166 if (pos == std::string::npos) { match =
false;
break; }
172 if (fname[i] != *globc) { match =
false; }
177 if (i + 1 == fname.size() &&
178 globc[1] !=
'\0' && globc[1] !=
'*') { match =
false; }
181 if (match) { flist.push_back(ent->
d_name); }
189 #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)