24 #include <coil/stringutil.h> 60 size_t len = strlen(path);
61 if (len > (
sizeof(return_dirname) /
sizeof(
char)))
63 len =
sizeof(return_dirname) /
sizeof(
char);
65 std::strncpy(return_dirname, path, len);
66 return_dirname[len] =
'\0';
68 const char delimiter(
'/');
69 char *p = std::strrchr(return_dirname, delimiter);
74 if(p != return_dirname)
79 dir_name =
dirname(return_dirname);
84 dir_name = return_dirname;
90 dir_name = return_dirname;
123 inline std::string
basename(
const char* path)
127 size_t len = strlen(path);
128 if (len > (
sizeof(p) /
sizeof(
char)))
130 len =
sizeof(p) /
sizeof(
char);
132 std::strncpy(p, path, len);
135 const char delimiter(
'/');
136 char *pdelimiter = std::strrchr(p, delimiter);
138 std::string base_name(p);
143 if(*(pdelimiter+1) ==
'\0')
151 base_name = pdelimiter;
156 if(*(pdelimiter+1) !=
'\0')
159 base_name = pdelimiter;
163 base_name = pdelimiter;
206 WIN32_FIND_DATAA *
fd;
237 if (name == 0) {
return 0; }
238 std::string
path(name);
239 if (path.empty()) {
return 0; }
242 if (*(path.end() - 1) !=
'\\' && *(path.end() - 1) !=
'/')
244 std::string::size_type pos(path.find(
"/"));
245 if (pos == std::string::npos) { path.push_back(
'\\'); }
246 else { path.push_back(
'/'); }
252 WIN32_FIND_DATAA* fd;
255 fd =
new WIN32_FIND_DATAA();
256 dhandle = FindFirstFileA(path.c_str(), fd);
257 if (dhandle == INVALID_HANDLE_VALUE) {
delete fd;
return 0; }
308 if (dir == 0) {
return 0; }
309 if (dir->
fd == 0) {
return 0;}
343 if (dir == 0) {
return -1; }
344 if (dir->
h != 0 && dir->
h != INVALID_HANDLE_VALUE)
348 if (dir->
fd != 0) {
delete dir->
fd; }
385 bool has_glob(
false);
388 if (path == 0) {
return flist; }
389 if (glob_str[0] !=
'\0') { has_glob =
true; }
392 if (dir_ptr == 0) {
return flist; }
399 const char* globc(glob_str);
400 std::string fname(ent->
d_name);
401 for (
size_t i(0); i < fname.size() && globc !=
'\0'; ++i, ++globc)
406 if (globc[1] ==
'\0') {
break; }
408 if (globc[1] ==
'*' || globc[1] ==
'+') { --i;
continue; }
412 size_t pos(fname.find(*globc, i));
413 if (pos == std::string::npos) { match =
false;
break; }
417 else if (*globc ==
'+')
420 if (globc[1] ==
'\0' && !(i + 1 < fname.size())) {
break; }
422 if (globc[1] ==
'*' || globc[1] ==
'+') { --i;
continue; }
426 size_t pos(fname.find(*globc, i + 1));
427 if (pos == std::string::npos) { match =
false;
break; }
433 if (fname[i] != *globc) { match =
false; }
438 if (i + 1 == fname.size() &&
439 globc[1] !=
'\0' && globc[1] !=
'*') { match =
false; }
442 if (match) { flist.push_back(ent->
d_name); }
452 #endif // COIL_FILE_H
const unsigned int MaxPathLength(1024)
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)