查找所有文件时不显示文件名
File name doesn't show up when looking for all files
我的代码有问题。我的查找文件函数不显示实际名称,但显示文件夹名称。有谁知道是什么导致了问题。path 将是用户的下载文件夹,path1 是需要移动文件的位置。是的,我在那个目录中有文件。
代码(适用于窗口):
bool* pointer = &doen;
WORD wait = 2500;
string path1 = getCurrentPath();
char userName[10];
DWORD userNameSize = sizeof(userName);
GetUserName(userName, &userNameSize);
string path = path1.substr(0, 3);
path += "users\";
path += userName;
path1 = path;
path += "\downloads";
path1 += "\documents\xxxx";
char const* plaatsD = path.c_str();
char const* plaatsF = path1.c_str();
userNameSize = NULL;
WIN32_FIND_DATA ffd;
TCHAR szDir[MAX_PATH];
HANDLE hFind = INVALID_HANDLE_VALUE;
DWORD dwError=0;
string str;
string str2;
string str3;
char const* a;
char const* b;
StringCchCopy(szDir, MAX_PATH, plaatsD);
while (herhalen)
{
Sleep(wait);
hFind = FindFirstFile(szDir, &ffd);
if (INVALID_HANDLE_VALUE == hFind)
continue;
do
{
str = ffd.cFileName;
if (str.find("xxx") != string::npos)
{
str2 = path;
str2 += "\" + str + ".b";
str3 = path1;
str3 += "\" + str + ".b";
a = str2.c_str();
b = str3.c_str();
try
{
CopyFile(a, b, true);
}
catch (exception)
{
}
a = NULL;
b = NULL;
}
}
while (FindNextFile(hFind, &ffd) != 0);
}
您必须将
星号 ( *
) (有关详细信息,请参阅 MSDN FindFirstFile) 到目录路径 ( szDir
) 才能枚举下载文件夹中的所有文件和文件夹。如果只想枚举文件,则追加*.*
。
因此,请像这样更改代码:
...
path += "users\";
path += userName;
path += "\*"; // Append an asterik.
...
正如@MRAB评论部分指出的那样,您还应该通过调用 FindClose(hFile)
来关闭查找句柄。
相关文章:
- 如何从QFile阅读?它显示该文件不可访问
- Visual Studio C++ 它只构建选项卡中显示的文件吗?
- 使用 Cmake 在 Qt Creator 中显示头文件
- 在C Windows程序中显示文本文件内容
- 使用 C++ 中的向量在新行上显示文本文件中的列
- 如何使用 Opengl 库显示文本文件中的 3D 点
- 如何在 Xcode 项目导航器中显示.txt文件
- 如何配置MSVC以使用__FILE__显示头文件的相对路径
- 如何在twebbrowser组件中显示HTML文件
- 使QT/C 程序显示其文件类型,如Windows上已知
- C++程序无法正确显示文本文件中的内容
- 有没有办法选择通过标准的OPENFILE对话框向用户显示哪些文件
- 如何使用流显示任何文件中的特殊和隐藏字符
- C++:帮助存储和显示输入文件变量
- 无法在QTreeView中显示.mp3文件
- 我可以使用什么开源C 库在专有的封闭源应用程序中显示PDF文件
- 显示 txt 文件详细信息
- 在日食中突出显示生成文件
- 如何在行和列中显示矩阵文件
- 如何显示顺序文件的内容