改变文件属性

#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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值