为什么不用API?
API中的FindFirstFile(),和FindNextFile()不是挺好用的吗?

解决方案 »

  1.   

    对了你还可以试试下面这个方法。
    _finddata_t fblk;
    long handle,result;
    char child[_MAX_PATH];
    child = "c:\\web\\*.htm";
    result = handle = _findfirst(child,&fblk);while(result !=-1)
    {
         if(((fblk.attrib&_A_SUBDIR)!=0)&&strcmp(fblk.name,".")&&strcmp
         (fblk.name,".."))
          {你想于什么就在这干吧。
            }
         result = _findnext(handle,&fblk);
    }
    _findlclose(handle);
    }
      

  2.   

    我对Windows的文件系统不太熟悉,望赐教!
      

  3.   

    在linux和unix中文件的信息是保存在它的目录文件中的,Windows中呢?
      

  4.   

    可以用CFileFind类的成员函数。
    例如:
    strPath = "c:\web\";
    strExtMask = "*.htm";
    void GetFileList(CString strPath, CString strExtMask)
    {
        CFileFind finder;
        CString strNewPth;//可以得到你想要的文件的路径 
        BOOL bWorking = finder.FindFile(strPath + strExtMask);    while (bWorking)
        {
            bWorking = finder.FindNextFile();
            //忽略 .和 ..文件; 否则就
            //死循环了!
            if (finder.IsDots())
                continue;
            //如果是目录,递归搜索        
            if (finder.IsDirectory())
            {
                strNewPath = finder.GetFilePath();
                strNewPath += "\\";
                strNewPath += strExtMask;
            }
            else
            {
                strNewPath = finder.GetFilePath();
            }
        }
        finder.Close();  
    }
      

  5.   

    if(((fblk.attrib&_A_SUBDIR)!=0)&&strcmp(fblk.name,".")&&strcmp
         (fblk.name,".."))
          //这句不好理解哦,可以写清楚一点么?谢了先  :)
      

  6.   

    windows的文件信息不是统一保存在一起的,就像我上面给你的代码,每个文件的信息保存在 _finddata_t这样的一个结构中,而这个结构是各文件在一起的,不过它是在文件的最前部,在这之后的部分才是文件的内容。
      

  7.   

    to vickowang(你的影子无所不在...) 
    谢谢! :)
    你的代码非常好,但CFileFind类是MFC的啊
    能有更底层的吗?
      

  8.   

    to : aqua_aqua(丁丁) 
    了解了,谢谢 ! :)
      

  9.   

    if(((fblk.attrib&_A_SUBDIR)!=0)&&strcmp(fblk.name,".")&&strcmp
         (fblk.name,".."))
          fblk.attrib&_A_SUBDIR 是代表这个目录下的子目录,
    同时在每个目录下都有两个系统自动生成的文件。这两个文件的文件名就是"."和"..",所以要去掉。
    唉呀,其这个条件语句没有也行了。我这是从原来的文件中截下来的。
      

  10.   

    to:丁丁
    能找到_findnext(..)这个函数的源代码吗?
    它保存在什么地方?
      

  11.   

    To: aqua_aqua(丁丁)
    函数名应该是 findfirst() 和 findnext(),没有下滑线_(Help 里有下滑线,
    但实际上没有下滑线)。另外,没有C里没有 findclose() 函数。
      

  12.   

    这我到没找,只知道它是包含在io.h中的。你可以用F11跟进去看一下。
      

  13.   

    有的。是有下滑线的。也有_findclose()这个函数。要不要我把那页MSDN贴出来。
      

  14.   

    _findclose
    Closes the specified search handle and releases associated resources.int _findclose( long handle );Function Required Header Compatibility 
    _findclose <io.h> Win 95, Win NT 
    For additional compatibility information, see Compatibility in the Introduction.LibrariesLIBC.LIB Single thread static library, retail version 
    LIBCMT.LIB Multithread static library, retail version 
    MSVCRT.LIB Import library for MSVCRT.DLL, retail version 
    Return ValueIf successful, _findclose returns 0. Otherwise, it returns –1 and sets errno to ENOENT, indicating that no more matching files could be found.ParameterhandleSearch handle returned by a previous call to _findfirstSystem Calls Routines |  _find, _wfind Function Overview
    --------------------------------------------------------------------------------
    Send feedback to MSDN.Look here for MSDN Online resources.