如何用vc++查找硬盘中创建最早的文件?(通过日期目录判断文件早晚)谢谢!!

解决方案 »

  1.   

    以下是按照文件名称查找,你自己改成按照时间查找就行了
    #define _WIN32_WINNT 0x0400#include <windows.h>
    #include <stdio.h>int main(int argc, char *argv[])
    {
      WIN32_FIND_DATA FindFileData;
      HANDLE hFind;  printf ("Target file is %s.\n", argv[1]);
      hFind = FindFirstFile(argv[1], &FindFileData);
      if (hFind == INVALID_HANDLE_VALUE) 
      {
        printf ("Invalid File Handle. GetLastError reports %d\n", GetLastError ());
        return (0);
      } 
      else 
      {
        printf ("The first file found is %s\n", FindFileData.cFileName);
        FindClose(hFind);
        return (1);
      }
    }
      

  2.   

    用MFCvoid SearchFile(CString path)
    {
    CFileFind finder;
    CString str = path + "\\*";
    BOOL b = finder.FindFile(str);

    while(b)
    {
    b = finder.FindNextFile();
    if(finder.IsDirectory())
    {
    if(!finder.IsDots())
    {
         SearchFile(finder.GetFilePath());
    }
    }
    else
    {
         CString str;
         CTime time;
         finder.GetLastWriteTime(time);
         //添加比较代码
    }
    }
    finder.Close(); 
    }