FindFirstFile, FindNextFile, FindClose

解决方案 »

  1.   

    BOOL DeleteDir(LPCTSTR pstr)
    {
    CString dirall(pstr);
    dirall+="\\*.*";
    CFileFind finder;
    BOOL bFind=(BOOL)finder.FindFile(dirall);
    while(bFind)
    {
    bFind=finder.FindNextFile();
    if(!finder.IsDots())
    {
    CString str = finder.GetFilePath();         
    if(finder.IsDirectory())
    {
    DeleteDir(str);
    }
    else
    {
    DeleteFile(str);
    }
    }
    }
    finder.Close();
    if(!RemoveDirectory(pstr))
    {
    AfxMessageBox("删除文件目录出错!");
    return FALSE;
    }
    return TRUE;
    }
    修改一下
      

  2.   

    http://www.csdn.net/expert/topic/461/461194.xml?temp=.4256861
      

  3.   

    BOOL b;        //定义一个布尔值,当所有的文件都遍历过之后,停止搜索
    CFileFind cf;
    int nItem;
    CString fName,fvideo,ftitle,fstime,fetime,fsize;
    CFileStatus status;
    CTime fctime,fmtime;
    double filesize;_chdir(lzPath);  //进入指定目录,lzPath是指定的路径。               
    b= cf.FindFile("*.*", 0);         //执行通配符(*.*)的搜索,为了派生类的FindFile实现多态保留,后一个参数必须为0 
    strcpy(strPath,lzPath); while (b)
    {
     b=cf.FindNextFile();             //继续前次调用FindFile生成的文件搜索。如果有更多的文件,则返回非0值;如果是最后一个文件,并且先前FindFile或FindNextFile的调用都返回非0,则返回值为0    fName = cf.GetFileName();        //获得找到文件的文件名
    ftitle = cf.GetFileTitle();           //得到指定文件的标题
    CFile::GetStatus(fName,status);

    fctime = status.m_ctime;                  //得到文件的创建时间
    fstime.format("%.4d-%.2d-%.2d%.2d:%.2d:%.2d",fctime.GetYear(),fctime.GetMonth(),
     fctime.GetDay(),fctime.GetHour(),fctime.GetMinute(),fctime.GetSecond());
         
    fmtime = status.m_mtime;     //得到文件最后修改时间
    fetime.format((“.4d-%.2d-%.2d%.2d:%.2d:%.2d",fmtime.GetYear(),fmtime.GetMonth(),          fmtime.GetDay(),fmtime.GetHour(),fmtime.GetMinute(),fmtime.GetSecond());

    filesize =(double) (lzStatus.m_size)/1024;     //文件大小
    fsize.format("%.3lfKB",filesize);
            
    //在列表视图中显示
    nItem = m_list.InsertItem(count,fName);
            m_list.SetItem(nItem,1,1,fvideo,NULL,0,0,0);
        m_list.SetItem(nItem,2,1,fstime,NULL,0,0,0);
    m_list.SetItem(nItem,3,1,fetime,NULL,0,0,0);
         m_list.SetItem(nItem,4,1,fsize,NULL,0,0,0);
    }
    这是我做的一个程序,遍历指定目录下所有文件并显示在列表框中,希望对你有帮助