23 #include <sys/types.h> 67 char path_name[strlen(path)+1];
68 strcpy(path_name, path);
69 std::string dir_name =
::dirname(path_name);
98 char path_name[strlen(path)+1];
99 strcpy(path_name, path);
100 std::string base_name =
::basename(path_name);
133 bool has_glob(
false);
136 if (path == 0) {
return flist; }
137 if (glob_str[0] !=
'\0') { has_glob =
true; }
139 DIR* dir_ptr(::opendir(path));
140 if (dir_ptr == 0) {
return flist; }
142 while ((ent = ::readdir(dir_ptr)) != 0)
147 const char* globc(glob_str);
148 std::string fname(ent->d_name);
149 for (
size_t i(0); i < fname.size() && *globc !=
'\0'; ++i, ++globc)
154 if (globc[1] ==
'\0') {
break; }
156 if (globc[1] ==
'*' || globc[1] ==
'+') { --i;
continue; }
160 size_t pos(fname.find(*globc, i));
161 if (pos == std::string::npos) { match =
false;
break; }
165 else if (*globc ==
'+')
168 if (globc[1] ==
'\0' && !(i + 1 < fname.size())) {
break; }
170 if (globc[1] ==
'*' || globc[1] ==
'+') { --i;
continue; }
174 size_t pos(fname.find(*globc, i + 1));
175 if (pos == std::string::npos) { match =
false;
break; }
181 if (fname[i] != *globc) { match =
false; }
186 if (i + 1 == fname.size() &&
187 globc[1] !=
'\0' && globc[1] !=
'*') { match =
false; }
190 if (match) { flist.push_back(ent->d_name); }
220 struct dirent **namelist=NULL;
222 int files = scandir(dir.c_str(), &namelist, NULL, NULL);
224 int files = scandir(const_cast<char*>(dir.c_str()), &namelist, NULL, NULL);
226 for (
int i=0; i<files; i++) {
227 std::string dname = namelist[i]->d_name;
228 if( dname !=
"." && dname !=
".." ){
230 std::string fullpath = dir +
"/" + dname;
232 struct stat stat_buf;
233 if(stat(fullpath.c_str(), &stat_buf) == 0){
234 if ((stat_buf.st_mode & S_IFMT) == S_IFDIR){
235 findFile(fullpath, filename, filelist);
239 if(dname == filename)
241 filelist.push_back(fullpath);
274 struct dirent **namelist=NULL;
276 int files = scandir(dir.c_str(), &namelist, NULL, NULL);
278 int files = scandir(const_cast<char*>(dir.c_str()), &namelist, NULL, NULL);
281 for (
int i=0; i<files; i++) {
282 std::string dname = namelist[i]->d_name;
283 if( dname !=
"." && dname !=
".." ){
285 std::string fullpath = dir +
"/" + dname;
287 struct stat stat_buf;
288 if(stat(fullpath.c_str(), &stat_buf) == 0){
289 if ((stat_buf.st_mode & S_IFMT) == S_IFDIR){
295 if(filesp.back() == ext)
297 filelist.push_back(fullpath);
309 #endif // COIL_FILE_H void findFile(std::string dir, std::string filename, coil::vstring &filelist)
Definition: File.h:218
std::vector< std::string > vstring
Definition: stringutil.h:45
std::string dirname(char *path)
Get a directory part than a file pass.
Definition: File.h:65
coil::vstring filelist(const char *path, const char *glob_str="")
Get file list.
Definition: File.h:129
std::string basename(const char *path)
Get a file name part than a file pass.
Definition: File.h:96
void getFileList(std::string dir, std::string ext, coil::vstring &filelist)
Definition: File.h:272
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty=false)
Split string by delimiter.
Common Object Interface Layer.
Definition: Affinity.h:28