Jostree Reprint Please specify the source http://www.cnblogs.com/jostree/p/4129616.html
1#include <string>2#include <fstream>3#include <iostream>4#include <stdlib.h>5#include <dirent.h>6#include <sys/types.h>7#include <sys/stat.h>8#include <string.h>9 using namespacestd;Ten voidList (Const Char*path,intLevel, vector<string> &Strvec) One { A structdirent* ent =NULL; -DIR *Pdir; -Pdir =opendir (path); the if(Pdir = =NULL) - { - return; - } + while(NULL! = (ent =Readdir (Pdir))) - { + if(Ent->d_type = =8) A { at //file -Strvec.push_back (ent->d_name); - } - Else - { - if(strcmp (Ent->d_name,".") ==0|| strcmp (Ent->d_name,"..") ==0) in { - Continue; to } + //Directory - string_path (path); the string_dirname (ent->d_name); * stringFulldirpath = _path +"/"+_dirname; $List (Fulldirpath.c_str (), Level +1, Strvec);Panax Notoginseng } - } the}
Linux gets all files under a folder