C++ 获取目录下的文件
2010-03-01 21:19
387 查看
#include <direct.h>
#include <string>
#include <vector>
#include <iomanip>
#include <ctime>
using namespace std;
void getFiles(string, vector<string>&);
int _tmain(int argc, _TCHAR* argv[])
{
vector<string> files;
getFiles(".", files);
// print the files get
for(int j=0; j<files.size(); j++){
cout << files[j] << endl;
}
return 0;
}
void getFiles(string path, vector<string>& files ){
//文件句柄
long hFile = 0;
//文件信息
struct _finddata_t fileinfo;
string p;
if ((hFile = _findfirst(p.assign(path).append("/*").c_str(),&fileinfo)) != -1) {
do {
//如果是目录,迭代之
//如果不是,加入列表
if ((fileinfo.attrib & _A_SUBDIR)){
if (strcmp(fileinfo.name,".") != 0 && strcmp(fileinfo.name,"..") != 0)
getFiles( p.assign(path).append("/").append(fileinfo.name), files );
} else {
files.push_back( p.assign(path).append("/").append(fileinfo.name) );
}
} while (_findnext( hFile, &fileinfo ) == 0);
_findclose(hFile);
}
}
#include <string>
#include <vector>
#include <iomanip>
#include <ctime>
using namespace std;
void getFiles(string, vector<string>&);
int _tmain(int argc, _TCHAR* argv[])
{
vector<string> files;
getFiles(".", files);
// print the files get
for(int j=0; j<files.size(); j++){
cout << files[j] << endl;
}
return 0;
}
void getFiles(string path, vector<string>& files ){
//文件句柄
long hFile = 0;
//文件信息
struct _finddata_t fileinfo;
string p;
if ((hFile = _findfirst(p.assign(path).append("/*").c_str(),&fileinfo)) != -1) {
do {
//如果是目录,迭代之
//如果不是,加入列表
if ((fileinfo.attrib & _A_SUBDIR)){
if (strcmp(fileinfo.name,".") != 0 && strcmp(fileinfo.name,"..") != 0)
getFiles( p.assign(path).append("/").append(fileinfo.name), files );
} else {
files.push_back( p.assign(path).append("/").append(fileinfo.name) );
}
} while (_findnext( hFile, &fileinfo ) == 0);
_findclose(hFile);
}
}
相关文章推荐
- C++ 如何获取目录下面的文件/文件的创建时间
- C++获取目录下的文件列表
- 【Unix编程】C/C++获取目录下文件或目录
- C++递归遍历获取某一目录下文件md5值
- linux C++获取目录下文件列表
- C++获取目录下所有文件列表函数
- c++学习之获取目录下的文件列表
- 【Linux编程】C/C++获取目录下文件或目录及linux中fork()函数详解(原创!!实例讲解)
- 【Unix编程】C/C++获取目录下文件或目录
- C++获取一个目录下的所有文件
- C/C++获取目录下的文件列表信息
- 获取c++执行文件的当前目录
- windows C++ 遍历目录,获取文件名和文件路径
- [C/C++]_[初级]_[使用C字符串(或者std::string)处理函数获取文件所在目录
- C/C++--C++获取目录下的文件列表
- c++判断文件是否存在,判断是文件还是目录,获取文件大小,获取程序所在路径
- C++获取一个目录下的所有文件
- windows C++ 遍历目录,获取文件名和文件路径
- C++获取指定目录下的所有文件
- [C/C++标准库]_[初级]_[获取文件的所在目录跨平台实现]