bool Filesystem::ls_r( TiObj out, std::string url ){ TiObj buffer = this->ls(url); for ( int i=0; i<buffer.size(); i++){ TiObj node = buffer.box(i); if ( node.is("Folder") ){ this->ls_r( out, node.atStr("url") ); } else { out.box() += node; } } return true; }
TiObj Filesystem::ls (std::string url) { TiObj out; this->log( __FUNCTION__ ); string real_url = this->path_set(url); DIR *dp; struct stat buf; struct dirent *ep; dp = opendir (real_url.c_str()); if (dp != NULL){ string item, item_url; while ( ep = readdir(dp) ){ if ( strcmp(ep->d_name,".")==0 || strcmp(ep->d_name,"..")==0 ) continue; item = path_add(url, ep->d_name); item_url = path_add(real_url, ep->d_name); if ( stat(item_url.c_str(), &buf) != -1 ){ if (S_ISREG (buf.st_mode) ){ string tmp = ep->d_name; TiObj novo; novo.set("class", this->file_type(ep->d_name) ); novo.set("name", tmp); novo.set( "url", item); out.box() += novo; } else if (S_ISDIR (buf.st_mode) ){ TiObj novo; this->folder_sysobj( novo, item_url ); novo.set( "url", item); if ( !novo.has("name") ) novo.set("name", ep->d_name); out.box() += novo; } } } closedir(dp); } else { return this->error( strerror(errno), url ); } return out; }