如何获得本机某个盘符下的所有文件名列表 如下: 程序自动实现获取某盘符下所有文件名?例如:我的c盘下有目录:winnt program document 程序执行後自动记录这些目和子目录的名字。保存在notepad中。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 #define ErrorHandler(a)WIN32_FIND_DATA FileData; HANDLE hSearch; BOOL fFinished = FALSE; // Start searching for .TXT files in the current directory. hSearch = FindFirstFile("c:\\*.*", &FileData); if (hSearch == INVALID_HANDLE_VALUE) { ErrorHandler("No files found."); } // Copy each .TXT file to the new directory // and change it to read only, if not already. while (!fFinished) { FileData.cFileName;//就是 if (!FindNextFile(hSearch, &FileData)) { if (GetLastError() == ERROR_NO_MORE_FILES) { // MessageBox( "No more files."); fFinished = TRUE; } else { ErrorHandler("Couldn't find next file."); } }} // Close the search handle. if (!FindClose(hSearch)) { ErrorHandler("Couldn't close search handle."); } hSearch = FindFirstFile("c:\\*.*", &FileData); 请问:这句得作用是什么啊? 这里给你一个比较完整的代码,可以实现你的要求://在你需要的地方调用ListFile("你的路径");即可,结果将输出到c:\\result.txt.void CFindString::ListFile(CString str){ CFile f; str += "\r\n"; f.Open("c:\\result.txt",CFile::modeCreate|CFile::modeWrite|CFile::modeNoTruncate); f.SeekToEnd(); f.Write(str,str.GetLength()); f.Close();}void CFindString::ListFolder(CString sPath){ CFileFind ff; BOOL bFound = ff.FindFile(sPath + "\\*.*"); while(bFound) { bFound = ff.FindNextFile(); CString sFilePath = ff.GetFilePath(); if(ff.IsDirectory()) { if(!ff.IsDots()) ListFolder(sFilePath); } else ListFile(sFilePath); }} 请问gamezealot(「Ryoga VS 我愛羅」:潜心练剑.挥剑问情...) :这里的Void CFindString::ListFolder(CString sPath)函数的作用是什么?它和前面的Void CFindString::ListFile(CString str)函数之间是什么样的逻辑关系?另外,有些问题如下:void CFindString::ListFile(CString str){ CFile f; str += "\r\n"; f.Open("c:\\result.txt",CFile::modeCreate|CFile::modeWrite|CFile::modeNoTruncate); f.SeekToEnd();//这里是什么意思? f.Write(str,str.GetLength());//这里什么意思? f.Close();}void CFindString::ListFolder(CString sPath)//这里写路径和上面的ListFile(CString str)写的//路径有什么关系?{ CFileFind ff; BOOL bFound = ff.FindFile(sPath + "\\*.*"); while(bFound) { bFound = ff.FindNextFile(); CString sFilePath = ff.GetFilePath(); if(ff.IsDirectory())//这句是什么意思? { if(!ff.IsDots())//这句是什么意思? ListFolder(sFilePath); } else ListFile(sFilePath); }} void ListFile(CString str){ CFile f; str += "\r\n"; f.Open("c:\\result.txt",CFile::modeCreate|CFile::modeWrite|CFile::modeNoTruncate); f.SeekToEnd(); f.Write(str,str.GetLength()); f.Close();}void ListFolder(CString sPath){ CFileFind ff; BOOL bFound = ff.FindFile(sPath + "\\*.*"); while(bFound) { bFound = ff.FindNextFile(); CString sFilePath = ff.GetFilePath(); if(ff.IsDirectory())//如果是目录 { if(!ff.IsDots())//每个目录下都有一个名字为..的目录,代表上层目录,所以在枚举的时候要跳过这个特殊目录,否则死循环 ListFolder(sFilePath); } else ListFile(sFilePath); }} f.SeekToEnd();//这里是什么意思?:::移动文件指针到文件结尾 f.Write(str,str.GetLength());//这里什么意思? ::::写入换行(\r\n)+文件名 void CFindString::ListFolder(CString sPath)//这里写路径和上面的ListFile(CString str)写的//路径有什么关系? 使用winsock2发送UDP包丢包严重。 付钱找人做LU分解实现,在vc平台下,qq详谈603250391 封装VLC的.dll文件生成ActiveX控件用于网页实时视频播放 如何修改CListView中CListCtrl默认的字体颜色和样式(Bold,underline)? 关于 SHCreateFolderViewEx的CALLBACK细节的问题 程序什么都不做,为什么一直占用CPU呢? CString与BYTE转换的问题 傅立叶变换的程序怎么写? 四个程序员在餐桌上的对话 怎么让文件给数组赋值,C语 如何用程序实现删除纪录密码和操作的行为? VC6程序调VC7生成的DLL报告连接错误
WIN32_FIND_DATA FileData;
HANDLE hSearch;
BOOL fFinished = FALSE;
// Start searching for .TXT files in the current directory.
hSearch = FindFirstFile("c:\\*.*", &FileData);
if (hSearch == INVALID_HANDLE_VALUE)
{
ErrorHandler("No files found.");
}
// Copy each .TXT file to the new directory
// and change it to read only, if not already.
while (!fFinished)
{
FileData.cFileName;//就是
if (!FindNextFile(hSearch, &FileData))
{
if (GetLastError() == ERROR_NO_MORE_FILES)
{
// MessageBox( "No more files.");
fFinished = TRUE;
}
else
{
ErrorHandler("Couldn't find next file.");
}
}
}
// Close the search handle.
if (!FindClose(hSearch))
{
ErrorHandler("Couldn't close search handle.");
}
请问:这句得作用是什么啊?
//在你需要的地方调用ListFile("你的路径");即可,结果将输出到c:\\result.txt.
void CFindString::ListFile(CString str)
{
CFile f;
str += "\r\n";
f.Open("c:\\result.txt",CFile::modeCreate|CFile::modeWrite|CFile::modeNoTruncate);
f.SeekToEnd();
f.Write(str,str.GetLength());
f.Close();
}
void CFindString::ListFolder(CString sPath)
{
CFileFind ff;
BOOL bFound = ff.FindFile(sPath + "\\*.*");
while(bFound)
{
bFound = ff.FindNextFile();
CString sFilePath = ff.GetFilePath();
if(ff.IsDirectory())
{
if(!ff.IsDots())
ListFolder(sFilePath);
}
else
ListFile(sFilePath);
}
}
void CFindString::ListFile(CString str)
{
CFile f;
str += "\r\n";
f.Open("c:\\result.txt",CFile::modeCreate|CFile::modeWrite|CFile::modeNoTruncate);
f.SeekToEnd();//这里是什么意思?
f.Write(str,str.GetLength());//这里什么意思?
f.Close();
}void CFindString::ListFolder(CString sPath)//这里写路径和上面的ListFile(CString str)写的
//路径有什么关系?
{
CFileFind ff;
BOOL bFound = ff.FindFile(sPath + "\\*.*");
while(bFound)
{
bFound = ff.FindNextFile();
CString sFilePath = ff.GetFilePath();
if(ff.IsDirectory())//这句是什么意思?
{
if(!ff.IsDots())//这句是什么意思?
ListFolder(sFilePath);
}
else
ListFile(sFilePath);
}
}
{
CFile f;
str += "\r\n";
f.Open("c:\\result.txt",CFile::modeCreate|CFile::modeWrite|CFile::modeNoTruncate);
f.SeekToEnd();
f.Write(str,str.GetLength());
f.Close();
}
void ListFolder(CString sPath)
{
CFileFind ff;
BOOL bFound = ff.FindFile(sPath + "\\*.*");
while(bFound)
{
bFound = ff.FindNextFile();
CString sFilePath = ff.GetFilePath();
if(ff.IsDirectory())//如果是目录
{
if(!ff.IsDots())//每个目录下都有一个名字为..的目录,代表上层目录,所以在枚举的时候要跳过这个特殊目录,否则死循环
ListFolder(sFilePath);
}
else
ListFile(sFilePath);
}
}
f.Write(str,str.GetLength());//这里什么意思? ::::写入换行(\r\n)+文件名
//路径有什么关系?