#include <windows.h>
#include <fstream>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
std::cout << "A new project." << endl;
//creates a fie as varuntest.txt
ofstream file("D:\\SaveZklsBmp\\a4.bmp\0", ios::app);
SYSTEMTIME createTime;
GetSystemTime(&createTime);
createTime.wDay = 3; //changes the day
createTime.wMonth = 01; //changes the month
createTime.wYear = 1921; //changes the year
createTime.wHour = 1; //changes the hour
createTime.wMinute = 1; //changes the minute
createTime.wSecond = 7; //changes the second
SYSTEMTIME lastWriteTime;
GetSystemTime(&lastWriteTime);
lastWriteTime.wDay = 07; //changes the day
lastWriteTime.wMonth = 04; //changes the month
lastWriteTime.wYear = 2012; //changes the year
lastWriteTime.wHour = 9; //changes the hour
lastWriteTime.wMinute = 37; //changes the minute
lastWriteTime.wSecond = 23; //changes the second
SYSTEMTIME lastAccessTime;
GetSystemTime(&lastAccessTime);
lastAccessTime.wDay = 20; //changes the day
lastAccessTime.wMonth = 07; //changes the month
lastAccessTime.wYear = 2017; //changes the year
lastAccessTime.wHour = 15; //changes the hour
lastAccessTime.wMinute = 31; //changes the minute
lastAccessTime.wSecond = 8; //changes the second
//creation of a filetimestruct and convert our new systemtime
FILETIME lastWriteFiletime;
SystemTimeToFileTime(&lastWriteTime, &lastWriteFiletime);
FILETIME createFiletime;
SystemTimeToFileTime(&createTime, &createFiletime);
FILETIME lastAccessFileTime;
SystemTimeToFileTime(&lastAccessTime, &lastAccessFileTime);
//getthe handle to the file
HANDLE filename = CreateFile("D:\\SaveZklsBmp\\a4.bmp\0", FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
//set the filetime on the file
SetFileTime(filename, &createFiletime, &lastAccessFileTime, &lastWriteFiletime);
//close our handle.
//CloseHandle(filename);
return 0;
}
改变文件属性
最新推荐文章于 2024-08-17 05:29:03 发布