请问,有什么函数或者控件可以逐一读出一个目录下的所有文件名?谢谢! 请问,有什么函数或者控件可以逐一读出一个目录下的所有文件名?谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 void CMyComDlg::OnButton1() { // TODO: Add your control notification handler code here AddList("C:\\myDir");}void CMyComDlg::AddList(char* DirName){ CFileFind tempFind; char tempFileFind[200]; sprintf(tempFileFind,"%s\\*.*",DirName); BOOL IsFinded=(BOOL)tempFind.FindFile(tempFileFind); while(IsFinded) { IsFinded=(BOOL)tempFind.FindNextFile(); if(!tempFind.IsDots()) { char foundFileName[200]; strcpy(foundFileName,tempFind.GetFileName().GetBuffer(200)); //还有子目录,子目录下的所有文件加入list if(tempFind.IsDirectory()) { char tempDir[200]; sprintf(tempDir,"%s\\%s",DirName,foundFileName); AddList(tempDir); } else { CString StrAdd; CString strFileName=tempFind.GetFileName(); //去掉扩展名 int EXTNameBegin = strFileName.Find('.'); if(EXTNameBegin==-1) { StrAdd=strFileName; } else { StrAdd=strFileName.Mid(0,EXTNameBegin); } //文件加入列表 m_Comb.AddString(StrAdd); } } } tempFind.Close();} 删除目录及目录下所有文件与子目录(Hermess发表于2002-5-24 22:10:27) VC++只提供了删除一个空目录的函数,而在实际应用中往往希望删除其下有很多子目录与文件的目录。为了实现这一功能,我编写了DeleteDirectory 函数,它可以实现这一功能。函数原型:BOOL DeleteDirectory(char *DirName);返回值:成功删除时返回TRUE,否则返回FALSE参数DirName为要删除的目录名,必须为绝对路径名,如“c:\\temp"。函数定义如下:BOOL DeleteDirectory(char *DirName){ CFileFind tempFind; char tempFileFind[200]; sprintf(tempFileFind,"%s\\*.*",DirName); BOOL IsFinded=(BOOL)tempFind.FindFile(tempFileFind); while(IsFinded) { IsFinded=(BOOL)tempFind.FindNextFile(); if(!tempFind.IsDots()) { char foundFileName[200]; strcpy(foundFileName,tempFind.GetFileName().GetBuffer(200)); if(tempFind.IsDirectory()) { char tempDir[200]; sprintf(tempDir,"%s\\%s",DirName,foundFileName); DeleteDirectory(tempDir); } else { char tempFileName[200]; sprintf(tempFileName,"%s\\%s",DirName,foundFileName); DeleteFile(tempFileName); } } } tempFind.Close(); if(!RemovwDirctory(DirName)) { MessageBox(0,"删除目录失败!","警告信息",MK_OK); return FALSE; } return TRUE;} HANDLE hFind;WIN32_FIND_DATA dataFind;BOOL bMoreFiles=TRUE;CString strFile;hFind=FindFirstFile(m_strMainDir+"\\*.*",&dataFind);while(hFind!=INVALID_HANDLE_VALUE && bMoreFiles ==TRUE){ if(dataFind.dwFileAttributes ==FILE_ATTRIBUTE_ARCHIVE) { int nChar =dataFind.cFileName[0]; if(islower(nChar)) nChar-=32; if(isalpha(nChar)) nChar-='A'; else nChar=26; m_treeFiles.InsertItem(dataFind.cFileName,hLetter[nChar];//在树中插入文件名 } bMoreFiles=FindNextFile(hFind,&dataFind);}FindClose(hFind); int Cselectfile::GetDetailFilePath(CString csFilePath){ WIN32_FIND_DATA fd; HANDLE m_handle; CString csFileName; //int dbfflag; csFileName=csFilePath+"\\*.*"; //csFilePath+="/"; m_handle=::FindFirstFile(csFileName,&fd); while(1) { if ((strcmp(fd.cFileName,".")==0 )||(strcmp(fd.cFileName,"..")==0)) { if(!::FindNextFile(m_handle,&fd)) break; continue; } else if(fd.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY) { GetDetailFilePath(csFilePath+"\\"+fd.cFileName); if(!::FindNextFile(m_handle,&fd)) break; continue; } else { //tempstr=fd.cFileName; //dbfflag=tempstr.Find(".dbf"); //if(dbfflag>0) //{ csProFileName[FileCount]=csFilePath+"\\"+fd.cFileName; FileCount++; //} if(!::FindNextFile(m_handle,&fd)) break; continue; } } return 1;} CRichEditCtrl控件中插入对象后,怎样设置单击该对象的响应函数 GDI泄露了吗? 我做的一个打印bmp的程序,为什么打印输出的位图那么小? 如何在ESPON打印机上定位打印? 如何探察到联众发送到本机的数据包? 位图处理 Win32下如何锁定窗口大小 大家给我看看我的代码!!有问题!!解决了,一定给高分!! 文件的路径选择对话框使用的是哪个API函数? 懂串口通讯的大虾来帮忙啊!!! 请教VC++6环境下OpenGL编程的一个入门问题,TOP有分! 在directx中怎样改变媒体的播放速度?
{
// TODO: Add your control notification handler code here
AddList("C:\\myDir");}
void CMyComDlg::AddList(char* DirName)
{
CFileFind tempFind;
char tempFileFind[200];
sprintf(tempFileFind,"%s\\*.*",DirName);
BOOL IsFinded=(BOOL)tempFind.FindFile(tempFileFind);
while(IsFinded)
{
IsFinded=(BOOL)tempFind.FindNextFile();
if(!tempFind.IsDots())
{
char foundFileName[200];
strcpy(foundFileName,tempFind.GetFileName().GetBuffer(200));
//还有子目录,子目录下的所有文件加入list
if(tempFind.IsDirectory())
{
char tempDir[200];
sprintf(tempDir,"%s\\%s",DirName,foundFileName);
AddList(tempDir);
}
else
{
CString StrAdd;
CString strFileName=tempFind.GetFileName();
//去掉扩展名
int EXTNameBegin = strFileName.Find('.');
if(EXTNameBegin==-1)
{
StrAdd=strFileName;
}
else
{
StrAdd=strFileName.Mid(0,EXTNameBegin);
}
//文件加入列表
m_Comb.AddString(StrAdd);
} }
}
tempFind.Close();
}
(Hermess发表于2002-5-24 22:10:27)
VC++只提供了删除一个空目录的函数,而在实际应用中往往希望删除其下有很多子目录与文件的目录。为了实现这一功能,我编写了DeleteDirectory
函数,它可以实现这一功能。函数原型:BOOL DeleteDirectory(char *DirName);
返回值:成功删除时返回TRUE,否则返回FALSE
参数DirName为要删除的目录名,必须为绝对路径名,如“c:\\temp"。函数定义如下:
BOOL DeleteDirectory(char *DirName)
{
CFileFind tempFind;
char tempFileFind[200];
sprintf(tempFileFind,"%s\\*.*",DirName);
BOOL IsFinded=(BOOL)tempFind.FindFile(tempFileFind);
while(IsFinded)
{
IsFinded=(BOOL)tempFind.FindNextFile();
if(!tempFind.IsDots())
{
char foundFileName[200];
strcpy(foundFileName,tempFind.GetFileName().GetBuffer(200));
if(tempFind.IsDirectory())
{
char tempDir[200];
sprintf(tempDir,"%s\\%s",DirName,foundFileName);
DeleteDirectory(tempDir);
}
else
{
char tempFileName[200];
sprintf(tempFileName,"%s\\%s",DirName,foundFileName);
DeleteFile(tempFileName);
}
}
}
tempFind.Close();
if(!RemovwDirctory(DirName))
{
MessageBox(0,"删除目录失败!","警告信息",MK_OK);
return FALSE;
}
return TRUE;
}
WIN32_FIND_DATA dataFind;
BOOL bMoreFiles=TRUE;
CString strFile;hFind=FindFirstFile(m_strMainDir+"\\*.*",&dataFind);while(hFind!=INVALID_HANDLE_VALUE && bMoreFiles ==TRUE)
{
if(dataFind.dwFileAttributes ==FILE_ATTRIBUTE_ARCHIVE)
{
int nChar =dataFind.cFileName[0];
if(islower(nChar))
nChar-=32;
if(isalpha(nChar))
nChar-='A';
else
nChar=26;
m_treeFiles.InsertItem(dataFind.cFileName,hLetter[nChar];//在树中插入文件名
}
bMoreFiles=FindNextFile(hFind,&dataFind);
}
FindClose(hFind);
{
WIN32_FIND_DATA fd;
HANDLE m_handle;
CString csFileName;
//int dbfflag;
csFileName=csFilePath+"\\*.*";
//csFilePath+="/";
m_handle=::FindFirstFile(csFileName,&fd);
while(1)
{
if ((strcmp(fd.cFileName,".")==0 )||(strcmp(fd.cFileName,"..")==0))
{
if(!::FindNextFile(m_handle,&fd))
break;
continue;
}
else if(fd.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY)
{
GetDetailFilePath(csFilePath+"\\"+fd.cFileName);
if(!::FindNextFile(m_handle,&fd))
break;
continue;
}
else
{
//tempstr=fd.cFileName;
//dbfflag=tempstr.Find(".dbf");
//if(dbfflag>0)
//{
csProFileName[FileCount]=csFilePath+"\\"+fd.cFileName;
FileCount++;
//}
if(!::FindNextFile(m_handle,&fd))
break;
continue;
} }
return 1;}