查找以特定字符串开头的文件 [英] find file starting with a certain string
本文介绍了查找以特定字符串开头的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何检查文件是否存在:
例如,我有很多文件:
Boba.txt
James.txt
Jamy.txt
Boby.txt
如何检查以Bob开头的文件是否存在?
解决方案
注意,我假设您使用的是Windows系统,并且文件位于同一目录中.>
您可以使用 FindFirstFile 和 FindNextFile 用于遍历目录的函数.前缀可以包含在搜索词中.
示例
std::string strSearch = "C:\\Some Directory\\Bob*";
WIN32_FIND_DATAA ffd;
HANDLE hFind = FindFirstFileA(strSearch .c_str(), &ffd);
do
{
std::string strFile = ffd.cFileName;
}
while (FindNextFileA(hFind, &ffd) != 0);
正确的错误检查以及如何处理目录留给读者练习.
I wonder how to check If a file exist or not :
For Example I have many files :
Boba.txt
James.txt
Jamy.txt
Boby.txt
How can I check if the file starting with Bob exists ?
解决方案
Note, I'm assuming that you're on a Windows system and that the files are in the same directory.
You can use the FindFirstFile and FindNextFile functions to iterate through a directory. The prefix can be included in search term.
Example
std::string strSearch = "C:\\Some Directory\\Bob*";
WIN32_FIND_DATAA ffd;
HANDLE hFind = FindFirstFileA(strSearch .c_str(), &ffd);
do
{
std::string strFile = ffd.cFileName;
}
while (FindNextFileA(hFind, &ffd) != 0);
Proper error checking and how to deal with directories is left as an exercise for the reader.
这篇关于查找以特定字符串开头的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文