/**************************************************************************** * CreateSubfolder * * Create recursive all subfolders to the given path ***************************************************************************/ bool CreateSubfolder(const char * fullpath) { if(!fullpath) return false; if(CheckFile(fullpath)) return true; string dirpath(fullpath); int length = dirpath.size()-1; while(dirpath[length] == '/') { dirpath.erase(length); --length; } string subpath(dirpath); size_t pos = subpath.rfind('/'); if(pos == string::npos) return false; if(subpath.size()-1 > pos) subpath.erase(pos+1); bool result = CreateSubfolder(subpath.c_str()); if(!result) return false; return (mkdir(dirpath.c_str(), 0777) != -1); }
bool Utils::rmdir(const std::string &path) { #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) return IOSUtils::rmdir(path); #elif (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) bool result = true; struct dirent *dirp; DIR *dp; if ((dp = ::opendir(path.c_str())) == NULL) { return false; } while (result && ((dirp = ::readdir(dp)) != NULL)) { if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0) { continue; } std::string subpath(path); subpath += "/"; subpath += dirp->d_name; struct stat substat; if (::stat(subpath.c_str(), &substat) < 0) { result = false; break; } //rm all of files under the specified dir recursively if (S_ISDIR(substat.st_mode)) { result = rmdir(subpath); } else if (S_ISREG(substat.st_mode)) { result = rmFile(subpath); } } if (::closedir(dp) < 0) { return false; } //now the dir is empty if (::rmdir(path.c_str()) < 0) { return false; } return result; #elif (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) return WP8Utils::getInstance().rmdir(path); #endif }
void AppManagerDirectory::TraversePath() { if (!appsp_.isNull()) { CTokenizedString subpath(appsp_,":"); CString dir = subpath.next(); while (!dir.isNull()) { GatherAppsFromASearchElement (dir); dir = subpath.next(); if (langVersionFound && dir == "/usr/dt/appconfig/appmanager/C") dir = subpath.next(); } } }
std::vector<std::string> Utils::getFilesOfDir(std::string path, std::string matchStr) { #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS || CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) std::vector<std::string> files; struct dirent *dirp; DIR *dp; if ((dp = ::opendir(path.c_str())) == NULL) { return files; } while ((dirp = ::readdir(dp)) != NULL) { if (strcmp(dirp->d_name, ".") == 0 || strcmp(dirp->d_name, "..") == 0) { continue; } std::string subpath(path); subpath += "/"; subpath += dirp->d_name; struct stat substat; if (::stat(subpath.c_str(), &substat) < 0) { break; } //rm all of files under the specified dir recursively if (S_ISDIR(substat.st_mode)) { } else if (S_ISREG(substat.st_mode)) { if (subpath.find(matchStr) != std::string::npos) { files.push_back(subpath); } } } ::closedir(dp); return files; #elif (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) std::vector<std::string> files; return files; #endif }
static vector<PathBits> GetDirectoriesAtPath(std::string& path) { vector<PathBits> directories; vector<string> paths; FileUtils::ListDir(path, paths); vector<string>::iterator i = paths.begin(); while (i != paths.end()) { string& subpath(*i++); if (subpath[0] == '.') continue; string fullPath(FileUtils::Join(path.c_str(), subpath.c_str(), NULL)); if (!FileUtils::IsDirectory(fullPath)) continue; directories.push_back(PathBits(subpath, fullPath)); } return directories; }
bool subpath(path_t const &root) const {return subpath(root.c_str());}