}
if (fData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
+ if (types & NO_DOT_OR_DOTDOT) {
+ if (!strcmp(fData.cFileName,".") || !strcmp(fData.cFileName,"..")) {
+ continue;
+ }
+ }
+
if (!(types & TYPE_DIR)) {
continue;
}
return result;
}
+ int filterLen = nameFilter.size();
+
while (true) {
struct dirent* entry = readdir(dp);
if (!entry) {
}
// skip hidden files (names beginning with '.') unless requested
- if (!(types & INCLUDE_HIDDEN) && (entry->d_name[0] == '.')) {
+ if (!(types & INCLUDE_HIDDEN) && (entry->d_name[0] == '.') &&
+ strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) {
continue;
}
-
- if (entry->d_type == DT_DIR) {
+
+ SGPath f = file(entry->d_name);
+ if (!f.exists()) {
+ continue; // stat() failed
+ }
+
+ if (f.isDir()) {
+ // directory handling
if (!(types & TYPE_DIR)) {
continue;
}
continue;
}
}
- } else if (entry->d_type == DT_REG) {
+ } else if (f.isFile()) {
+ // regular file handling
if (!(types & TYPE_FILE)) {
continue;
}
} else {
- continue; // ignore char/block devices, fifos, etc
+ // block device /fifo/char file, ignore
+ continue;
}
-
+
if (!nameFilter.empty()) {
- if (strstr(entry->d_name, nameFilter.c_str()) == NULL) {
+ int nameLen = strlen(entry->d_name);
+ if (nameLen < filterLen) {
+ continue; // name is shorter than the filter
+ }
+
+ char* nameSuffix = entry->d_name + (nameLen - filterLen);
+ if (strcmp(nameSuffix, nameFilter.c_str())) {
continue;
}
}
return result;
}
+bool Dir::exists() const
+{
+ return _path.isDir();
+}
+
SGPath Dir::file(const std::string& name) const
{
SGPath childPath = _path;