首页 > 代码库 > 获取Windows某一目录下的所有文件名

获取Windows某一目录下的所有文件名

#include <sys/types.h>
#include <dirent.h>
 
 
std::vector<std::string> get_all_filename(char* dirname)
{
     DIR *dp;
     struct dirent* dirp;
     std::vector<std::string> filename_vector;
     if((dp = opendir(dirname)) == NULL)
     {
          printf("this dir maybe not exist");
     }
     while((dirp = readdir(dp)) != NULL)
     {
          filename_vector.push_back(dirp->d_name);
     }
     closedir(dp);
     return filename_vector;
}

获取Windows某一目录下的所有文件名