windows C++ 遍历目录,获取文件名和文件路径
2017-08-04 18:06
531 查看
void GetFiles(const char* srcPath, vector<string> &filesPath, vector<string>& filesName)
{
WIN32_FIND_DATAA ffd;
memset(&ffd, 0, sizeof(ffd));
string path = srcPath;
path.append("\\*");
HANDLE hFind = FindFirstFileA(path.c_str(),
&ffd);
do {
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (!strcmp(ffd.cFileName,".") || !strcmp(ffd.cFileName,
".."))
continue;
string newPath;
newPath.append(srcPath).append("\\").append(ffd.cFileName);
getFileName(files, newPath.c_str(),
imageName);
}
else
{
char filePath[MAX_LEN_256] = { 0 };
sprintf_s(filePath, "%s/%s", srcPath,
ffd.cFileName);
imageName.push_back(ffd.cFileName);
files.push_back(filePath);
}
} while (FindNextFileA(hFind, &ffd)
!= 0);
FindClose(hFind);
}
void GetFiles(const char* srcPath, vector<string> &filesPath, vector<string>& filesName)
{
WIN32_FIND_DATAA ffd;
memset(&ffd, 0, sizeof(ffd));
string path = srcPath;
path.append("\\*");
HANDLE hFind = FindFirstFileA(path.c_str(),
&ffd);
do {
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (!strcmp(ffd.cFileName,".") || !strcmp(ffd.cFileName,
".."))
continue;
string newPath;
newPath.append(srcPath).append("\\").append(ffd.cFileName);
getFileName(files, newPath.c_str(),
imageName);
}
else
{
char filePath[MAX_LEN_256] = { 0 };
sprintf_s(filePath, "%s/%s", srcPath,
ffd.cFileName);
imageName.push_back(ffd.cFileName);
files.push_back(filePath);
}
} while (FindNextFileA(hFind, &ffd)
!= 0);
FindClose(hFind);
}
{
WIN32_FIND_DATAA ffd;
memset(&ffd, 0, sizeof(ffd));
string path = srcPath;
path.append("\\*");
HANDLE hFind = FindFirstFileA(path.c_str(),
&ffd);
do {
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (!strcmp(ffd.cFileName,".") || !strcmp(ffd.cFileName,
".."))
continue;
string newPath;
newPath.append(srcPath).append("\\").append(ffd.cFileName);
getFileName(files, newPath.c_str(),
imageName);
}
else
{
char filePath[MAX_LEN_256] = { 0 };
sprintf_s(filePath, "%s/%s", srcPath,
ffd.cFileName);
imageName.push_back(ffd.cFileName);
files.push_back(filePath);
}
} while (FindNextFileA(hFind, &ffd)
!= 0);
FindClose(hFind);
}
void GetFiles(const char* srcPath, vector<string> &filesPath, vector<string>& filesName)
{
WIN32_FIND_DATAA ffd;
memset(&ffd, 0, sizeof(ffd));
string path = srcPath;
path.append("\\*");
HANDLE hFind = FindFirstFileA(path.c_str(),
&ffd);
do {
if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if (!strcmp(ffd.cFileName,".") || !strcmp(ffd.cFileName,
".."))
continue;
string newPath;
newPath.append(srcPath).append("\\").append(ffd.cFileName);
getFileName(files, newPath.c_str(),
imageName);
}
else
{
char filePath[MAX_LEN_256] = { 0 };
sprintf_s(filePath, "%s/%s", srcPath,
ffd.cFileName);
imageName.push_back(ffd.cFileName);
files.push_back(filePath);
}
} while (FindNextFileA(hFind, &ffd)
!= 0);
FindClose(hFind);
}
相关文章推荐
- windows C++ 遍历目录,获取文件名和文件路径
- windows下获取文件上传路径报错:java.io.FileNotFoundException: (文件名、目录名或卷标语法不正确。)
- windows下用c++和python遍历目录下的文件夹并删除所有文件名为xx的文件
- 获取任意文件路径及文件名、运行程序当前目录
- windows服务等获取文件路径文件目录方法
- C++程序中获取不带文件路径和后缀的文件名
- C/C++遍历目录下的所有文件(Windows/Linux)
- windows命令行文件中获取bat文件所在目录相关路径
- C#通过正规表达式获取文件根目录、路径、文件名、后缀名
- 获取指定目录下指定类型所有文件的全路径及文件名
- C++实现Linux和Windows下遍历指定目录下的文件
- c++判断文件是否存在,判断是文件还是目录,获取文件大小,获取程序所在路径
- windows 批处理 获取当前目录及子目录的所有文件路径
- C++获取某路径下所有文件名,ifstream打开某路径下的指定文件
- java 读取目录及子目录下指定文件名的路径 并放到一个List数组里面返回遍历和写到文件里
- C/C++解析文件路径,获取盘符、路径、文件名及扩展名
- HDFS 读取、写入、遍历目录获取文件全路径、append文件创建或者写入报错问题分析
- C++程序中获取不带文件路径和后缀的文件名
- C/C++解析文件路径,获取盘符、路径、文件名及扩展名
- c++--------获取某个路径下所有文件的文件名,读写TXT文件到新的文件