发新话题
打印

[转载]文件时间修改器源码

[转载]文件时间修改器源码

来自:zhouzhen's Blog
复制内容到剪贴板
代码:
// setTime.cpp : Defines the entry point for the console application.
//

#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

void usage()
{
     system("cls.exe");
     printf("-------------------------------------------------------\n"
            "\tsetTime Ver 1.0  zhouzhen[E.S.T], 2005/3/5\n"
            "\thttp://www.eviloctal.com, [email]zhouzhen@yeah.net[/email]\n"
          "\t      文件时间修改器 1.0"
            "\n\n"
            "\tUsage:  \tsetTime OldFile NewFile\n"
            "\tExample: \tsetTime hello.asp eviloctal.asp\n"
            "--------------------------------------------------------\n"
            );
     exit(0);
}

int main(int argc, char* argv[])
{
     HANDLE hFileOld, hFileNew;
     FILETIME OcreateTime, OLastAccessTime, OLastWriteTime;
     const FILETIME *pCreationTime, *pLastAccessTime, *pLastWriteTime;

          if (argc!=3)
          usage();
     else{

          hFileOld = createFile(argv[1], GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
          if (hFileOld == INVALID_HANDLE_VALUE)
          {
              printf("Cannot open %s. Error:%x\n", argv[1], GetLastError());
              exit(1);
              
          }

          hFileNew = createFile(argv[2], GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
          if (hFileNew == INVALID_HANDLE_VALUE)
          {
              printf("Cannot open %s. Error:%x\n", argv[2], GetLastError());
              exit(2);
              
          }

          GetFileTime(hFileOld , &OcreateTime, &OLastAccessTime, &OLastWriteTime);
     
      
          pCreationTime = &OcreateTime;
      pLastAccessTime = &OLastAccessTime;
      pLastWriteTime = &OLastWriteTime;
         
          SetFileTime(hFileNew, pCreationTime, pLastAccessTime,pLastWriteTime);

         
          CloseHandle(hFileNew);
          CloseHandle(hFileOld);

          printf("All is done! Enjoy yourself\n");



     }
     return 0;
}
广告位招商! 联系人:neeao E-Mail:neeaocn(at)gmail.com Msn:neeao@hotmail.com Site:http://www.neeao.com

TOP

发新话题