C ++查找所有.wav文件 [英] C++ Find all .wav files
问题描述
这是我做了到目前为止,它只搜索C驱动器根文件夹,我现在不知道该怎么做。我知道我应该使用某种循环,但我不知道如何实际做,没有逻辑的方式,我可以想到这样做。
void finddata()
{
MessageBox(NULL,finddata called,Started,MB_OK | MB_ICONINFORMATION);
WIN32_FIND_DATA FindFileData; //指向接收关于找到的文件或目录的信息的WIN32_FIND_DATA结构的指针。
HANDLE hFind; //用于检查返回值
hFind = FindFirstFile(C://*.wav,& FindFileData);
if(hFind == INVALID_HANDLE_VALUE)
{
MessageBox(NULL,INVALID_HANDLE_VALUE,Failed,MB_OK | MB_ICONINFORMATION);
}
else
{
字符串文件;
file = FindFileData.cFileName;
file.append(|);
MessageBox(NULL,file.c_str(),YO,MB_OK | MB_ICONASTERISK); // string.c_str()to conv to LPCSTR
FindClose(hFind);
}
}
MessageBox到底是作为测试,我会删除它以后。我目前正在学习C ++,这是一个初学者的项目,所以我可以得到一个悬念。
此外,字符串的大小有任何限制数据类型?感谢。
显然,你确实需要一个 FindNextFile
并重复使用某种类型的循环,直到它返回一个没有更多的文件返回码。
要搜索整个磁盘,您需要在当前目录(根目录)中查找目录,并为每个目录搜索目录可以通过递归调用 finddata
(将该目录的名称作为参数添加到函数中)来实现,或者在代码中实现堆栈以跟踪您所在的目录,和哪一个走回到下一级。
我故意不为你写代码,而是描述你需要做什么,因为你是一个学习编程。我在1985年这样做了。
I'm trying to create an application in C++ that would search all .wav files on the disk (including all subfolders and their subfolders and so on..., whole disk search, like antivirus search on Avast and similar) and store them in a string and save to a text file later on. I'm having troubles figuring out the way on how to actually do this and I could use some help.
This is what I done so far, it's only searching the C drive root folder and I don't know what to do now. I know I should use a loop of some sort but I don't know how to actually do it, there's no logical way that I can think to do it.
void finddata()
{
MessageBox(NULL, "finddata called", "Started", MB_OK | MB_ICONINFORMATION);
WIN32_FIND_DATA FindFileData; // A pointer to the WIN32_FIND_DATA structure that receives information about a found file or directory.
HANDLE hFind; // Used to check the return value
hFind = FindFirstFile("C://*.wav", &FindFileData);
if(hFind == INVALID_HANDLE_VALUE)
{
MessageBox(NULL, "INVALID_HANDLE_VALUE", "Failed", MB_OK | MB_ICONINFORMATION);
}
else
{
string file;
file = FindFileData.cFileName;
file.append("|");
MessageBox(NULL, file.c_str(), "YO", MB_OK | MB_ICONASTERISK); // string.c_str() to conv to LPCSTR
FindClose(hFind);
}
}
The MessageBox at the end is just there as a test, I'll remove it later on. I'm currently learning C++ and this is a sort of a beginner's project so I can get a hang of it.
Also, are there any limitations in size for the string data type? Thanks.
Obviously, you do indeed need a FindNextFile
call, and repeat that using a loop of some sort, until it returns a "no more files" return code.
To then search the entire disk, you will need to look for directories in the "current directory" (the root directory), and for every directory search into it - you can do that either by calling finddata
recursively (adding the name of the directory as an argument to the function), or implement a stack in the code to track which directory you are in, and which one to "walk back to" for the next level.
I'm intentionally NOT writing the code for you, but describing what you need to do, since you are the one learning programming. I did this sort of thing in 1985 or so.
这篇关于C ++查找所有.wav文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!