Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7199870
  • 博文数量: 510
  • 博客积分: 12019
  • 博客等级: 上将
  • 技术积分: 6836
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-01 16:46
文章分类

全部博文(510)

文章存档

2022年(2)

2021年(6)

2020年(59)

2019年(4)

2018年(10)

2017年(5)

2016年(2)

2015年(4)

2014年(4)

2013年(16)

2012年(47)

2011年(65)

2010年(46)

2009年(34)

2008年(52)

2007年(52)

2006年(80)

2005年(22)

分类: C/C++

2006-07-04 15:20:10

1、打开目录
   常用于目录选择
CString SelectPath()
{
 char filename[255];
 BROWSEINFO info;
 info.hwndOwner = NULL ;
 info.pidlRoot = (LPCITEMIDLIST)NULL;
 info.pszDisplayName = filename;
 info.lpszTitle = "请选择文件夹:";
 info.ulFlags = BIF_BROWSEFORCOMPUTER | BIF_RETURNONLYFSDIRS  ;
 info.lpfn = NULL;
 info.lParam = 0;
 info.iImage = 0 ;
 LPITEMIDLIST idlist = SHBrowseForFolder(&info);
 char szpath[255];
 SHGetPathFromIDList(idlist,szpath);
 return szpath;
}
 
2、打开文件
  常用于文件选择
 
 CFileDialog dlg(true, NULL, NULL, NULL, "*.txt|*.txt||");
 if(dlg.DoModal() == IDOK)
 {
   CString strFile = dlg.GetPathName();
 }
 
3、遍历目录
   采用递归方式,输出文件名称和路径
 
#include "windows.h"
void BrowseFile(string& strFile)
{
 int nRet =0;
 string dirTemp;
 string strTemp;
 WIN32_FIND_DATA FindFileData;
 HANDLE hFind =INVALID_HANDLE_VALUE;
 string strDir = strFile;
 nRet = strDir.find_last_of("\\");
 if(nRet  strDir+="\\*.*";
 else
  strDir+="*.*";
 hFind = FindFirstFile((char*)strDir.c_str(), &FindFileData);
 if (hFind == INVALID_HANDLE_VALUE)
  return ;
 
 while (FindNextFile(hFind, &FindFileData))
 {
  
  if(FindFileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
  { 
   if((strcmp(FindFileData.cFileName, ".") == 0)|| (strcmp(FindFileData.cFileName, "..") == 0))
    continue;
   dirTemp=strFile;
   
   dirTemp=dirTemp+"\\";
   dirTemp+= FindFileData.cFileName;
   BrowseFile(dirTemp);//递归调用
  }
  else //到达最低层的文件
  {

   strTemp=strFile;
   strTemp=strFile+"\\";
   strTemp+=FindFileData.cFileName; 
   nRet = FindStr(strFileName);
   cout<
  }
 }
   FindClose(hFind);
 
}
 
 
 
 
 
阅读(1693) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~