void listfiles(const char *dir, const char *ext, vector<char *> &files, int (__cdecl *sf)(const char **, const char **)) { listdir(dir, ext, files); string s; if(homedir[0]) { formatstring(s)("%s%s", homedir, dir); listdir(s, ext, files); } loopv(packagedirs) { formatstring(s)("%s%s", packagedirs[i], dir); listdir(s, ext, files); } #ifndef STANDALONE listzipfiles(dir, ext, files); #endif if(sf) { // sort and remove doubles files.sort(sf); for(int i = files.length() - 1; i > 0; i--) { if(!strcmp(files[i], files[i - 1])) delstring(files.remove(i)); } } }
int cyg_start(void) { #if defined(CYGPKG_FS_FAT) int err; int existingdirents=-1; #endif DBG("Start USB MSD application\n\r"); #if defined(CYGPKG_FS_FAT) // Mount RAM disk partition 1 err = mount( "/dev/ramdisk0/1", "/", "fatfs" ); if( err < 0 ) SHOW_RESULT( mount, err ); err = chdir( "/" ); if( err < 0 ) SHOW_RESULT( chdir, err ); checkcwd( "/" ); // Display list of all files/directories from root listdir( "/", true, -1, &existingdirents ); // Play around with the file-system, create / copy / // compare files createfile( "/foo", 1000 ); checkfile( "foo" ); copyfile( "foo", "fee" ); checkfile( "fee" ); comparefiles( "foo", "/fee" ); DBG("<INFO>: mkdir bar\n"); // Create new directory err = mkdir( "/bar", 0 ); if( err < 0 ) SHOW_RESULT( mkdir, err ); // Display list of all files/directories from root listdir( "/" , true, existingdirents+3, NULL ); // Umount file-system err = umount( "/" ); if( err < 0 ) SHOW_RESULT( umount, err ); #endif // Start Mass Storage Service usbs_msd_start(); // Start scheduler cyg_scheduler_start(); }
/* * Function: flash_cli_cmd_ls * Description: FS_CLI list all the file and dir for current dir * Input: * Output: 0 - pass */ int flash_cli_cmd_ls(void) { listdir( ".", NULL); return 0; }
void listdir(const char *name, int level){ DIR *dir; struct dirent *entry; if (!(dir = opendir(name))) return; if (!(entry = readdir(dir))) return; do { if (entry->d_type == DT_DIR) { char path[MAXLINE]; int len = snprintf(path, sizeof(path)-1, "%s/%s", name, entry->d_name); path[len] = 0; if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) continue; // printf("%*s[%s]\n", level*2, "", entry->d_name); // recursive listdir(path, level + 1); } else{ char path[MAXLINE]; int len = snprintf(path, sizeof(path)-1, "%s/%s", name, entry->d_name); path[len] = 0; printf("file path: %s\n", path); } } while (entry = readdir(dir)); closedir(dir); }
int main(int argc, char** argv) { listdir(".",0); for(i=0;i<count;i++) printf("%s\n",file_name[i]); return 0; }
void listdir(const char *name, int level) { DIR *dir; struct dirent *entry; struct stat stbuf; if (!(dir = opendir(name))) return; if (!(entry = readdir(dir))) return; do { if (entry->d_type == DT_DIR) { char path[1024]; int len = snprintf(path, sizeof(path)-1, "%s/%s", name, entry->d_name); path[len] = 0; if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) continue; printf("%*s[%s]\n", level*2, "", entry->d_name); listdir(path, level + 1); } else stat(entry->d_name, &stbuf); printf("%*s%d- %s\n", level*2, "", stbuf.st_size, entry->d_name); } while (entry = readdir(dir)); closedir(dir); }
static int listpath(const char *name, int flags) { struct stat s; int err; /* * If the name ends in a '/', use stat() so we treat it like a * directory even if it's a symlink. */ if (name[strlen(name)-1] == '/') err = stat(name, &s); else err = lstat(name, &s); if (err < 0) { perror(name); return -1; } if ((flags & LIST_DIRECTORIES) == 0 && S_ISDIR(s.st_mode)) { if (flags & LIST_RECURSIVE) printf("\n%s:\n", name); return listdir(name, flags); } else { /* yeah this calls stat() again*/ return listfile(NULL, name, flags); } }
void listdir(const char *name, int level) { DIR *dir; struct dirent *entry; if (!(dir = opendir(name))) return ; if (!(entry = readdir(dir))) return ; do { struct stat sb; lstat(entry->d_name,&sb); if (S_ISDIR(sb.st_mode)) { char path[1024]; int len = snprintf(path, sizeof(path)-1, "%s/%s", name, entry->d_name); if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) continue; names[total]=strdup(path+5); total++; listdir(path, level + 1); } else{ char path[1024]; int len = snprintf(path, sizeof(path)-1, "%s/%s", name, entry->d_name); names[total]=strdup(path+5); total++; } } while ((entry = readdir(dir))); closedir(dir); return ; }
bool listdir(std::string rootPath, int level, std::vector<std::string> &vectPath) { DIR *dir = NULL; struct dirent *entry = NULL; if (!(dir = opendir(rootPath.c_str()))) return false; if (!(entry = readdir(dir))) return false; do { if (entry->d_type == DT_DIR) { char path[1024]; int len = snprintf(path, sizeof(path)-1, "%s%c%s", rootPath.c_str(), FilePathSeparator, entry->d_name); path[len] = 0; if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) continue; // printf("%*s[%s]\n", level*2, "", entry->d_name); listdir(path, level + 1, vectPath); } else { std::string pathTemp = rootPath; std::string name = entry->d_name; pathTemp.append(1, FilePathSeparator); pathTemp.append(name); vectPath.push_back(pathTemp); // printf("%*s- %s\n", level*2, "", entry->d_name); printf("%s\n", pathTemp.c_str()); } } while ((entry = readdir(dir)) != NULL); closedir(dir); return true; }
int main(int argc, char **argv) { struct fsw_posix_volume *vol; int i; if (argc != 2) { fprintf(stderr, "Usage: lslr <file/device>\n"); return 1; } for (i = 0; fstypes[i]; i++) { vol = fsw_posix_mount(argv[1], fstypes[i]); if (vol != NULL) { fprintf(stderr, "Mounted as '%s'.\n", fstypes[i]->name.data); break; } } if (vol == NULL) { fprintf(stderr, "Mounting failed.\n"); return 1; } listdir(vol, "/boot/", 0); catfile(vol, "/boot/vmlinuz-3.5.0-19-generic"); fsw_posix_unmount(vol); return 0; }
static int listdir(struct fsw_posix_volume *vol, char *path, int level) { struct fsw_posix_dir *dir; struct dirent *dent; int i; char subpath[4096]; dir = fsw_posix_opendir(vol, path); if (dir == NULL) { fprintf(stderr, "opendir(%s) call failed.\n", path); return 1; } while ((dent = fsw_posix_readdir(dir)) != NULL) { for (i = 0; i < level*2; i++) fputc(' ', stderr); fprintf(stderr, "%d %s\n", dent->d_type, dent->d_name); if (dent->d_type == DT_DIR) { snprintf(subpath, 4095, "%s%s/", path, dent->d_name); listdir(vol, subpath, level + 1); } } fsw_posix_closedir(dir); return 0; }
bool listdir(JSNFS *nfs, DIR *dir, std::string fullpath, int strip) { dirent *cur; if (dir == NULL) { fprintf(stderr, "null dir given\n"); return false; } while ((cur = readdir(dir)) != NULL) { std::string newpath = fullpath + "/" + cur->d_name; const char *vpath = &newpath.c_str()[strip]; if (cur->d_type & DT_DIR) { if (strcmp(cur->d_name, ".") == 0 || strcmp(cur->d_name, "..") == 0) { continue; } if (!nfs->mkdir(vpath, strlen(vpath))) { fprintf(stderr, "Failed to create dir %s\n", vpath); return false; } if (!listdir(nfs, opendir(newpath.c_str()), newpath, strip)) { return false; } } else if (cur->d_type & DT_REG) { // PtrAutoDelete<Stream *> stream(Stream::Create(newpath.c_str())); Stream *stream = Stream::Create(newpath.c_str()); if (stream == NULL) { fprintf(stderr, "Could not create stream for file %s\n", newpath.c_str()); return false; } char *content; size_t len; if (!stream->getContentSync(&content, &len, true)) { fprintf(stderr, "Could not read stream for file %s\n", newpath.c_str()); return false; } if (!nfs->writeFile(vpath, strlen(vpath), content, len)) { fprintf(stderr, "Failed to write file %s\n", vpath); return false; } fprintf(stderr, "Saved file : %s\n", vpath); } } closedir(dir); return true; }
int main(int argc, char *argv[]) { int c; char *fnam = NULL; FILE *fp = stdout; char *_root = NULL; while ((c = getopt (argc, argv, "f:r:")) != EOF) switch (c) { case 'f': fnam = optarg; break; case 'r': _root = optarg; break; default: break; } if (fnam != NULL) { if ((fp = fopen(fnam, "w")) == NULL) Err("Unable to open for write"); } if (_root != NULL) { if (chdir(_root) < 0) Err("chdir"); } if (optind < argc) { char *dnam = NULL; struct stat fs; while (optind < argc) { dnam = argv[optind++]; if (stat(dnam, &fs) < 0) Err("stat"); if (fs.st_mode & S_IFDIR) listdir(dnam, fp); else { // printf("delete %s\n", dnam); unlink(dnam); } } } else listdir("./", fp); if (fnam != NULL) fclose(fp); exit(0); }
int main (int argc, char *argv[]) { if (argc != 2) return -1; listdir (argv[1]); return 0; }
int Directory::GetFilesCount(const CString& path, const bool& recursive) { std::string path_utf8 = stringWstingToUtf8String(path.c_str()); std::vector<std::string> files; listdir (path_utf8.c_str(), recursive, files); return files.size()+1; }
int main() { listdir("recursos/"); int ta = total_archivos(); printf("Total Archivos guardados: %i\n",ta); procesarArchivos(); return 0; }
FrameNet FrameNetBuilder::read(){ FrameNet fn = FrameNet(); for(auto filename:listdir(frames_path)){ std::string path=frames_path+filename; Frame *frame = frame_builder.build_frame(path); fn.add_frame(frame); } this->read_relations(fn); return fn; }
void init() { ON_CALL(*this, opened()) .WillByDefault(Return(true)); ON_CALL(*this, exists(_)) .WillByDefault(Return(false)); ON_CALL(*this, listdir()) .WillByDefault(Return(std::vector<std::string>())); ON_CALL(*this, changed(_)) .WillByDefault(Return(std::time(nullptr))); }
//int stat(char *, struct stat *); void fsize(char *name) { struct stat stbuf; if (stat(name, &stbuf) == -1) { fprintf(stderr, "fsize: can`t access %s\n", name); } if ((stbuf.st_mode & S_IFMT) == S_IFDIR) { //dirwalk(name, fsize); listdir(name, 1); } //printf("%8ld %s\n", stbuf.st_size, name); }
int main(int argc, char * argv[]) { int mtm = 0; int uid = -1; char username[32]; int c; int count = 0; int userFilter = 0; int sameVol = 0; int vol = 0; while ( (c = getopt(argc, argv, "u:m:")) != -1) { switch (c) { case 'u': sscanf(optarg, "%d", &uid); sscanf(optarg, "%s", &username); userFilter = 1; break; case 'm': sscanf(optarg, "%d", &mtm); break; case 'x': sameVol = 1; break; case '?': break; default: printf ("?? getopt returned character code 0%o ??\n", c); } } char searchpath[PATH_MAX+1]; sscanf(argv[optind],"%s",searchpath); if (sameVol == 1) { struct stat sp; // DIR * pd = opendir(realpath(searchpath,NULL)); // struct dirent * entry = readdir(pd); lstat(realpath(searchpath,NULL),&sp); vol = sp.st_dev; } if ((uid == -1) && (userFilter ==1 )) { struct passwd * uidInfo; uidInfo = getpwnam(username); uid = uidInfo->pw_uid; } listdir(searchpath,uid,mtm,vol,count); return 0; }
int listfiles(const char *dir, const char *ext, vector<char *> &files) { int dirs = 0; if(listdir(dir, ext, files)) dirs++; string s; if(homedir[0]) { formatstring(s)("%s%s", homedir, dir); if(listdir(s, ext, files)) dirs++; } loopv(packagedirs) { formatstring(s)("%s%s", packagedirs[i], dir); if(listdir(s, ext, files)) dirs++; } #ifndef STANDALONE dirs += listzipfiles(dir, ext, files); #endif return dirs; }
static int Embed(int argc, char **argv) { Core::Context *ncx = initNidiumJS(); JSContext *cx = ncx->getNJS()->getJSContext(); if (argc <= 1) { printf("$ %s <path> [prefix] [> out]\n", argv[0]); return 1; } DIR *dir = opendir(argv[1]); if (!dir) { fprintf(stderr, "Can't open dir %s\n", argv[1]); } JS_BeginRequest(cx); JSNFS *nfs = new JSNFS(cx); bool ok; if (argc == 3) { std::string prefix = "/"; prefix += argv[2]; fprintf(stderr, "Create prefix %s...\n", prefix.c_str()); nfs->mkdir(prefix.c_str(), strlen(prefix.c_str())); ok = listdir(nfs, dir, argv[1], strlen(argv[1])); } else { ok = listdir(nfs, dir, argv[1], strlen(argv[1])); } nfs->save(DIR2NFS_OUTPUT); JS_EndRequest(cx); delete ncx; return ok ? 0 : 1; }
std::string make_temp_fname (const char* tmpdir, const char* prefix) { // if directory not passed in, guess one std::string tn = temp_dir (tmpdir);; // if prefix not passed in, use default if (!prefix) prefix = DEFAULT_TEMP_FILE_PREFIX; // get temp directory listing StrVec dircontent = listdir (tn); // find all entries matching prefix and having numeric postfix, get list of numbers UintSet postfixes; unsigned prefix_len = prefix ? strlen (prefix) : 0; for (StrVec::iterator ii = dircontent.begin (); ii != dircontent.end (); ii ++) { // check if prefix matches if (prefix_len && (ii->substr (0, prefix_len) != prefix)) continue; // check if postfix is numeric and get the number unsigned number = 0; std::string::iterator sitr; for (sitr = ii->begin () + prefix_len; sitr != ii->end (); sitr ++) { number *= 10; if (!isdigit (*sitr)) break; else number += *sitr - '0'; } if (sitr != ii->end ()) continue; // store number to postfixes set postfixes.insert (number); } // now retrieve the numbers using first gap // make a set for quick presence check unsigned prev = 0; for (UintSet::iterator nitr = postfixes.begin (); nitr != postfixes.end (); nitr ++) if (prev + 1 < *nitr) break; // found the gap in sequence else prev = *nitr; if (prev == std::numeric_limits<unsigned>::max ()) // just for sanity :) ers << "No more temp file names available for prefix " << (prefix ? prefix : "") << " in directory " << tn << Throw; // prev + 1 is the right number std::ostringstream name (tn, std::ios::out | std::ios::app); name << PATH_SEPARATOR; if (prefix) name << prefix; name << prev + 1; return name.str (); }
void *doftp(void *sd) { int req, msg_ok, ret = 0,dump; long ssock = (long)sd; ret = auth_user(ssock); if (ret == -1) { close(ssock); return; } while(1) { req = 0; if((readn(ssock,(char *)&req,sizeof(req))) < 0) { printf("server: read error %d\n",errno); return; } req = ntohs(req); switch(req) { case STOREFILE: status=sendfile(ssock); break; case REQUESTFILE: status=recvfile(ssock); break; case MKDIR: status=makedir(ssock); break; case LIST: status=listdir(ssock); break; case DELETEFILE: status=deletefile(ssock); break; case END: printf("Client sent request to end connection.\n"); close(ssock); return; default: break; } if(status==-1) break; } return; }
static void recursedir(const char *path) { int fd; char buf[1024]; char newpath[1024]; int len; /* * Open it. */ fd = open(path, O_RDONLY); if (fd<0) { err(1, "%s", path); } /* * List the directory. */ while ((len = getdirentry(fd, buf, sizeof(buf)-1)) > 0) { buf[len] = 0; /* Assemble the full name of the new item */ snprintf(newpath, sizeof(newpath), "%s/%s", path, buf); if (!aopt && buf[0]=='.') { /* skip this one */ continue; } if (!strcmp(buf, ".") || !strcmp(buf, "..")) { /* always skip these */ continue; } if (!isdir(newpath)) { continue; } listdir(newpath, 1 /*showheader*/); if (Ropt) { recursedir(newpath); } } if (len<0) { err(1, "%s", path); } close(fd); }
static void test_folder(const char *folder) { char **files; int num_files, i; files = NULL; num_files = 0; listdir(folder, &files, &num_files); for (i = 0; i < num_files; ++i) { if (strcmp("cs", get_filename_ext(files[i]))) continue; test_file(files[i]); } }
static void listitem(const char *path, int showheader) { if (!dopt && isdir(path)) { listdir(path, showheader || Ropt); if (Ropt) { recursedir(path); } } else { print(path); } }
bool TestListdir::process () { typedef std::vector <std::string> StrVec; StrVec file_list; const char *dir_name = "."; file_list = listdir (dir_name); o_ << "Listing of directory '" << dir_name << "':" << std::endl; StrVec::iterator i = file_list.begin(); while (i != file_list.end()) { o_ << (*i).c_str () << std::endl; i ++; } return true; }
int main() { std::string DIRN; std::vector <std::string> LIST; DIRN= std::string("."); LIST = std::vector <std::string> (); listdir(DIRN, LIST); for (unsigned int i = 0;i < files.size();i++) { std::cout << files[i] << std::endl; } return 0; }
int main(void) { listdir("/proc", 0); pstree(); ps(); return 0; }