C++设置文件修改时间
来源:互联网 发布:php throw exception 编辑:程序博客网 时间:2024/06/07 22:44
VS2010新建控制台空项目,加入C++代码:
#include <Windows.h>#include <stdio.h>bool ConvertFileTimeToLocalTime(const FILETIME *lpFileTime, SYSTEMTIME *lpSystemTime){if (!lpFileTime || !lpSystemTime) {return false;}FILETIME ftLocal;FileTimeToLocalFileTime(lpFileTime, &ftLocal);FileTimeToSystemTime(&ftLocal, lpSystemTime);return true;}bool ConvertLocalTimeToFileTime(const SYSTEMTIME *lpSystemTime, FILETIME *lpFileTime){if (!lpSystemTime || !lpFileTime) {return false;}FILETIME ftLocal;SystemTimeToFileTime(lpSystemTime, &ftLocal);LocalFileTimeToFileTime(&ftLocal, lpFileTime);return true;}int main(){HANDLE hFile;FILETIME ftCreate, ftAccess, ftWrite;SYSTEMTIME stCreate, stAccess, stWrite;int year, month, day;hFile = CreateFile(L"C:\\1.txt", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);if (INVALID_HANDLE_VALUE == hFile) {printf("CreateFile error: %d", GetLastError());ExitProcess(0);}GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite);ConvertFileTimeToLocalTime(&ftCreate, &stCreate);ConvertFileTimeToLocalTime(&ftAccess, &stAccess);ConvertFileTimeToLocalTime(&ftWrite, &stWrite);printf("yyyy-MM-dd:");scanf("%d-%d-%d", &year, &month, &day);stAccess.wYear = stWrite.wYear = year;stAccess.wMonth = stWrite.wMonth = month;stAccess.wDay = stWrite.wDay = day;ConvertLocalTimeToFileTime(&stAccess, &ftAccess);ConvertLocalTimeToFileTime(&stWrite, &ftWrite);SetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite);CloseHandle(hFile);return 0;}
只修改年月日,时分秒不变。
- C++设置文件修改时间
- 设置文件属性,修改文件存取时间
- pb9获取文件创建时间、最后修改时间及设置最后修改时间的方法
- 修改“文件修改时间”
- [Object C]_[初级]_[文件修改创建时间和修改时间]
- 批量修改字幕文件中的时间,c语言实现
- Java 通过 JNA (Java Native Access) 获取、设置 Windows 操作系统的文件创建时间、文件修改时间、文件访问时间
- 文件时间修改器
- 修改文件时间
- 修改文件时间
- linux修改文件时间
- 修改文件时间
- 修改文件时间
- Linux修改文件时间
- utime修改文件时间
- 文件修改时间
- 修改文件时间
- 批量修改文件时间
- c++11版生产者-消费者
- IOS学习笔记06---C语言函数
- Strategy(策略模式)
- 聚类算法初探(三)直接聚类法
- 正则表达式(javascript)学习总结
- C++设置文件修改时间
- jquery Ztree v3.5 实例2 自定义显示在节点前的图片
- IOS学习笔记07---C语言函数-printf函数
- 如何用Apache TCPMon来截获SOAP消息
- PHP5.5 + Apache2.4.4 初体验(64位)
- ios模拟器 奇怪的中文字
- “_beginthread”: 即使使用参数相关的查找,也未找到标识符 解决方法
- JPEG编解码过程详解
- Node.js测试