aihot  2017-05-24 18:36:31  OpenCV |   查看评论   

测试代码:test_directory.cpp:

  1. #include <string>  
  2. #include <vector>  
  3. #include <iostream>  
  4. #include "directory.hpp"  
  5. #include "test_directory.hpp"  
  6.   
  7. int test_directory_GetListFiles()  
  8. {  
  9.     fbc::Directory dir;  
  10.   
  11.     std::string path = "E:/GitCode/OpenCV_Test/test_images";  
  12.     std::string exten = "*.jpg"//"*";  
  13.     bool addPath = false//true;  
  14.   
  15.     // 遍历指定文件夹下的所有文件,不包括指定文件夹内的文件夹  
  16.     std::vector<std::string> filenames = dir.GetListFiles(path, exten, addPath);  
  17.   
  18.     std::cout << "file names: " << std::endl;  
  19.     for (int i = 0; i < filenames.size(); i++)  
  20.         std::cout <<"    "<< filenames[i] << std::endl;  
  21.   
  22.     return 0;  
  23. }  
  24.   
  25. int test_directory_GetListFilesR()  
  26. {  
  27.     fbc::Directory dir;  
  28.   
  29.     std::string path = "E:/GitCode/OpenCV_Test/test_images";  
  30.     std::string exten = "*";  
  31.     bool addPath = true//false  
  32.   
  33.     // 遍历指定文件夹下的所有文件,包括指定文件夹内的文件夹  
  34.     std::vector<std::string> allfilenames = dir.GetListFilesR(path, exten, addPath);  
  35.   
  36.     std::cout << "all file names: " << std::endl;  
  37.     for (int i = 0; i < allfilenames.size(); i++)  
  38.         std::cout <<"    "<< allfilenames[i] << std::endl;  
  39.   
  40.     return 0;  
  41. }  
  42.   
  43. int test_directory_GetListFolders()  
  44. {  
  45.     fbc::Directory dir;  
  46.   
  47.     std::string path = "E:/GitCode/OpenCV_Test/test_images";  
  48.     std::string exten = "*d*"//"*"  
  49.     bool addPath = false//true  
  50.   
  51.     // 遍历指定文件夹下的所有文件夹,不包括指定文件夹下的文件  
  52.     std::vector<std::string> foldernames = dir.GetListFolders(path, exten, addPath);  
  53.   
  54.     std::cout << "folder names: " << std::endl;  
  55.     for (int i = 0; i < foldernames.size(); i++)  
  56.         std::cout << "    "<< foldernames[i] << std::endl;  
  57.   
  58.     return 0;  
  59. }  
 

除特别注明外,本站所有文章均为 赢咖4注册 原创,转载请注明出处来自OpenCV代码提取:遍历指定目录下指定文件的实现

留言与评论(共有 0 条评论)
   
验证码:
[lianlun]1[/lianlun]