1. //Windows
    2. #include<iostream>
    3. #include<string>
    4. #include <io.h>
    5. void readFileNameInDir(IN string strDir, INOUT vector<string>& vFileFullPath) {
    6. long handle;//文件句柄
    7. struct _finddata_t fileInfo;//文件结构体
    8. handle = _findfirst(strDir.c_str(), &fileInfo);//第一次查找,获取文件句柄
    9. while (!_findnext(handle, &fileInfo)) {
    10. vFileFullPath.push_back(fileInfo.name)
    11. }
    12. _findclose(handle);
    13. }//readFileNameInDir()
    14. //Linux
    15. #include <string>
    16. #include <vector>
    17. #include <dirent.h>
    18. vod readFileNameInDir(IN string strDir, INOUT vector<string>& vFileFullPath) {
    19. struct dirent* pDirent;
    20. DIR* pDir = opendir(strDir.c_str());
    21. if (pDir != NULL) {
    22. while ((pDirent = readdir(pDir)) != NULL) {
    23. string strFileName = pDirent->d_name;
    24. string strFileFullPath = strDir + "/" + strFileName;
    25. vFileFullPath.push_back(strFileFullPath);
    26. }
    27. vFileFullPath.erase(vFileFullPath.begin(), vFileFullPath.begin() + 2);//前两个存储的是当前路径和上一级路径,所以要删除
    28. }
    29. }//readFileNameInDir()