|
VC 修改文件时间源码
#include <stdio.h>
#include "windows.h"
#include "iostream.h"
#include "stdlib.h"
int main(int argc, char* argv[])
{
if (argc == 8)
{
FILETIME ft,ft1;
SYSTEMTIME systime;
int gxm,gxm1,gxm2,gxm3,gxm4,gxm5;
gxm=atoi(argv[7]); //秒
gxm=gxm - 1;
gxm1=atoi(argv[2]); //年份
gxm2=atoi(argv[3]); //月份
gxm3=atoi(argv[4]); //日
gxm4=atoi(argv[5]); //小时
gxm5=atoi(argv[6]); //分钟
systime.wYear = gxm1;
systime.wMonth = gxm2;
systime.wDay = gxm3;
systime.wHour = gxm4;
systime.wMinute = gxm5;
systime.wSecond = gxm; //想要改变秒,必须要少一位
SystemTimeToFileTime(&systime, &ft);
LocalFileTimeToFileTime(&ft,&ft1); //把时间转换UTC
HANDLE hFile;
hFile = CreateFile(argv[1], GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ| FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile== INVALID_HANDLE_VALUE)
{
printf("open't the file[!]...................................error\n");
}
SetFileTime(hFile, &ft1, &ft1, &ft1);
CloseHandle(hFile);
printf("changed[!]...................................OK\n");
return 0;
}
printf("名称:修改文件访问时间、创建时间和最后修改时间的工具\n");
cout << "文件使用方法:" << argv[0] << " F:\\test1.exe 2008 1 25 17 25 10"<<endl;
return 0;
} |
|
|