各位:请问用VC怎么样扫描硬盘,得到路径下的文件名????? 我要把该文件名存起来。谢谢参与和回答。。!!!!!

解决方案 »

  1.   

    参考以下文章:用VisualC++6.0递归查找目录树 
    北京信息工程学院 
    马文晓 ---- 在SDI项目内,通过使用CFileDialog和CFileFind类,不仅可以实现Windows桌面上现有的查找功能,而且可以灵活扩展查找条件.例如,下面的程序将在VisualC++6.0的Output窗口内逐行输出c:\windows下所有长度小于500字节的只读文件: #include < direct.h > /*含有
    _getcwd,_chdir原型*/
    void f0(){
    char x[256],y[256];
    CFileDialog fd(TRUE);
    /*用TRUE值构造"File Open"对话框*/
    _getcwd(x,256); /*
    当前工作目录存入x数组*/  if (fd.DoModal()==IDOK){
    /*在CfileDialog对话过程中,
    先选定c:\windows目录,
    再选定其下一普通文件,如Notepad.exe,
    或输入一不存在的文件,如f0.non*/
    _getcwd(y,256); 
    /*当前工作目录c:\windows存入y数组*/
    f1(y); /*用y内容调用f1函数*/
    }
    _chdir(x); /*当前工作目录置回x内容*/
    }void f1(CString x){
    BOOL b;CFileFind f;
    /*考虑到递归,只能使用局部变量*/
    _chdir(x); b=f.FindFile("*.*");
     /*当前工作目录置成实参x,
    然后查其下所有文件*/
    while(b){
    b=f.FindNextFile();
    if (f.IsDirectory()){
    /*当前文件是目录*/
    if (!f.IsDots())
    {   f1(f.GetFilePath()); 
    /*目录文件非"."和"..",
    则用全路径调用自身*/
    }
    }
    else 
    if (f.IsReadOnly()&&f.GetLength
    ()< 500){
    afxDump< < "\n";
    afxDump< < f.GetFilePath(); 
    /*输出长度小于500字节的只读文件的文件*/
    }
      }
    }
    ---- 待程序正常结束后,Output窗口将显示执行结果.另外,经用CmemoryState类检查,已证明此段程序未导致内存泄漏.
      

  2.   

    The FindFirstFile function opens a search handle and returns information about the first file whose name matches the specified pattern. Once the search handle is established, you can use the FindNextFile function to search for other files that match the same pattern. When the search handle is no longer needed, close it by using the FindClose function.