[文章作者] zhouzhen[E.S.T]
[信息来源]
http://zhouzhen.blogchina.com
用来修改文件时间的小工具
Usage: setTime OldFile NewFile
Example: setTime hello.asp eviloctal.asp
OldFile 为时间较早的文件,NewFile 为时间较新的文件。运行程序后 NewFile的时间和OldFile的时间一样了,都为较早的时间。
PS:以前浪子他们也写过,练练编程。
附件[setTime.rar]:
http://blog.blogchina.com/upload ... 306104336131782.rar
MD5: ca6f67cde2bfa4347405d9b930d2f58c
-------------------------------------------------------
setTime Ver 1.0 zhouzhen[E.S.T], 2005/3/5
http://www.eviloctal.com,
zhouzhen@yeah.net
文件时间修改器 1.0
Usage: setTime OldFile NewFile
Example: setTime hello.asp eviloctal.asp
--------------------------------------------------------
复制内容到剪贴板
代码:
// 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;
}