- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想遍历目录的所有子目录以找到所有 .snt 文件。但是 FindFirstFile 和 FindNextFile 只搜索给定的目录,而不是它的子目录。
具体来说,我正在搜索路径 F:\Program Files (x86)\Amnesia\sounds\
中 sounds 文件夹的所有子文件夹我尝试将 F:\\Program Files (x86)\\Amnesia\\sounds\\*\\*.snt
传递给 FindFirstFile 但它返回垃圾。执行此操作的正确方法是什么?
#include <windows.h>
#include <stdio.h>
#include <iostream.h>
#include <conio.h>
void main()
{
char path[100]="F:\\Program Files (x86)\\Amnesia\\sounds\\*\\*.snt";
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
hFind = FindFirstFile(path, &FindFileData);
printf("The first file found is %s\n",FindFileData.cFileName);
getch();
}
最佳答案
好吧,“手动”递归。
下面是递归的思路。缺少的是基于扩展名的文件检测。
void file_search_rec(const char *folder)
{
char path[MAX_PATH] ;
WIN32_FIND_DATA FindFileData;
HANDLE hFind;
strcpy(path, folder) ;
strcat(path, "\\*") ;
FindFirstFile(path, &FindFileData) ;
if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
char subpath[MAX_PATH] ;
strcpy(subpath, folder) ;
strcat(subpath, FindFileData.cFileName) ;
// here make the recursive call on subpath
file_search_rec(subpath) ;
}
}
关于c++ - 你如何让 FindFirstFile 打开你给它的路径的子目录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31117830/
FindFirstFile win32 函数失败。请解决问题。谢谢 #include #include #include #include #define ValidDir(data) strcmp(
可以使用 FindFirstFile() 将文件从一个目录移动或复制到另一个目录吗?既然返回的是句柄,那这个句柄可以用来做吗? 最佳答案 不,它甚至不是内核句柄。此句柄可以仅传递给FindNextFi
我使用 FindFirstFile(...) 函数编写了查找文件的程序。但是当我尝试打印这个函数的输出时,控制台窗口中打印了几串未知字符。我读了一些帖子,上面写着尝试使用 wcout 而不是 cout
我使用函数 FindFirstFile() 但我只收到内存地址 - 而不是文件名。 #include #include #include using namespace std; int mai
我在方法中使用 FindFirstfFile() 来读取文件夹中的文件在此方法中,我将目录路径作为函数参数之一读取 Functionname(structname struct_var,char *p
你好,我的代码有问题。 LPCSTR mergeString(LPCSTR firstString, std::string secondString) { string convertedS
我正在尝试创建一个强大的递归文件夹删除器功能。 使用普通目录工作得很好。 当我创建一个“硬核”目录时出现问题,例如: C:\test\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x\x
是否可以使用 Windows API 函数 FindFirstFile 来搜索多种文件类型,例如 *.txt 和 *.doc同一时间? 我尝试用 '\0' 分隔模式,但它不起作用 - 它只搜索第一个模
我想获取特定目录中所有文件的列表。为此 |我使用以下代码 void GetFileListing(std::list& listing, std::string directory, std::str
我一直在使用 FindFirstFile 和 FindNextFile 时遇到问题,我需要让它们将所有 dll 列出到一个数组中,但我无法让它列出任何文件。我试过使用和编辑来自 MSDN 的示例代码,
我正在尝试使用 Windows API 中的 FindFirstFile 函数,我以前用过它,但现在找不到了。它只是告诉我找不到标识符。我有它的其他变体 FindFirstFileExW、FindFi
我正在使用以下代码获取有关文件系统目录的信息: LPCTSTR pStrPath = L"D:\\1"; WIN32_FIND_DATA wfd; HANDLE hDummy = ::FindFirs
我正在尝试使用 FindFirstFile 函数来遍历我所有的 .txt 文件,但是我收到了 INVALID_VALUE_HANDLE 错误试试吧,这是我的功能: int search(LPSTR l
我正在使用以下超 super 简单代码列出目录中的所有文件(Windows 8.1、Visual Studio Express 2013、C++): #include #include #incl
首先我会说我对宽字符串和 Unicode 支持基本上一无所知。我让 QString 和 QFile 为我处理 99% 的时间,但我正在尝试编译其他人为 VC6 编写的库。 当我在 Qt Creator
MSDN 说: HANDLE WINAPI FindFirstFile( LPCTSTR lpFileName, LPWIN32_FIND_DATA lpFindFileData ); lpFileN
Windows API FindFirstFile()和FindFirstFileEx()接受通配符以作为搜索路径,例如“星号(*)或问号(?)”。我实际上无法在哪里找到它接受哪些其他字符(如果有)的
我在尝试运行在服务器上运行的 Winapi::findFirstFile 时遇到问题。我已经尝试复制 WinapiServer 类上的方法,并更改一些行,如下所示: server static con
我想遍历目录的所有子目录以找到所有 .snt 文件。但是 FindFirstFile 和 FindNextFile 只搜索给定的目录,而不是它的子目录。 具体来说,我正在搜索路径 F:\Program
我正在尝试查找所有驱动器上的所有文件,操作系统是 Windows 8 std::string FolderName = "C:\\"; FindAllFiles(FolderName)
我是一名优秀的程序员,十分优秀!