c++遍历目录文件
2014-09-01 00:00
225 查看
摘要: 取网上demo修改而成
发现一个问题, 对中文目录不支持。。。待优化
#include <iostream> #include <string> #include <cstring> #include <vector> #include <io.h> #include <windows.h> using namespace std; void getFileList(const string& sPath,vector<string>& fileList); void getFile(const string& sPath,vector<string>& fileList,_finddata_t& file) { if(file.attrib == _A_SUBDIR) { string filename = file.name; if(filename == "." || filename == "..") { return ; } string sAddPath = sPath; sAddPath += filename; sAddPath += "\\"; getFileList(sAddPath,fileList); } else { string sAddPath = sPath; sAddPath += file.name; fileList.push_back(sAddPath); } } void getFileList(const string &sPath,vector<string>& fileList) { struct _finddata_t file; string sPathLast, sPath2 = sPath; long hFile; if ( sPath[sPath.length()-1] != '\\' ) sPath2 += "\\"; sPathLast = sPath2 + "*"; hFile = _findfirst(sPathLast.c_str(), &file); if(hFile == -1) return; else getFile(sPath2,fileList,file); while(_findnext(hFile, &file) != -1) { getFile(sPath2,fileList,file); } } int main(int argc,char** argv) { string fileDir("E:"); vector<string> rfileList; getFileList(fileDir,rfileList); for(size_t i=0;i<rfileList.size();i++) { cout<<rfileList[i]<<endl; } system("pause"); return 0; }
发现一个问题, 对中文目录不支持。。。待优化
相关文章推荐
- paip.c++ qt 目录遍历以及文件操作
- paip.c++ qt 目录遍历以及文件操作
- c++遍历创建文件目录
- Win32下C++遍历目录和文件的源码
- x64下vs2013 C++遍历目录下所有文件使用_findnext()调试时中断
- Win32下C++遍历目录和文件的源码
- x64下vs2013 C++遍历目录下所有文件使用_findnext()调试时中断
- C++遍历读取文件夹(仅限当前目录而不深入)下的文件
- c++ 遍历目录下文件和文件夹
- Win32下C++遍历目录和文件的源码
- 通过C/C++遍历目录下的所有文件
- c++遍历目录下文件
- C++ 遍历目录所有文件并判断是否为目录
- c++ 遍历目录查找文件
- C++ 遍历目录下文件
- C++ 遍历目录下的所有文件
- C++遍历文件夹及判断某一文件或目录是否存在
- Linux下 C++遍历目录下所有文件
- C++遍历目录,并把目录里超过7天的文件删除(跨平台windows&linux)
- Win32下C++遍历目录和文件的源码