如何在Windows下修改文件时间戳???

BoweirrKing 2004-11-22 04:23:52
创建、修改、访问三者的都要改。

有例子或源码当然最好了,能给个思路也行,谢谢各位了!

Email: ghostex@126.com
...全文
1710 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaqq 2004-11-22
  • 打赏
  • 举报
回复
发了,呵呵,接收!
oyljerry 2004-11-22
  • 打赏
  • 举报
回复
FILETIME lpCreationTime1; // 文件夹的创建时间
FILETIME lpLastAccessTime1; // 对文件夹的最近访问时间
FILETIME lpLastWriteTime1; // 文件夹的最近修改时间
FILETIME ftime1;
SYSTEMTIME newstime;
SYSTEMTIME stime1;
newstime.wYear = 2002;
newstime.wMonth = 10;
newstime.wDay = 30;
newstime.wHour = 12;
newstime.wMinute = 0;
newstime.wSecond = 0;
SystemTimeToFileTime(&newstime, &lpCreationTime1); // 转换成文件的时间格式
SystemTimeToFileTime(&newstime, &lpLastAccessTime1);
SystemTimeToFileTime(&newstime, &lpLastWriteTime1);
BOOL retval = SetFileTime(hHtml,&lpCreationTime1,&lpLastAccessTime1,&lpLastWriteTime1);
if(retval)
m_ListBox.AddString("修改文件时间属性成功");

else
m_ListBox.AddString("修改文件时间属性失败");

strTime.Format("%d",GetLastError());
m_ListBox.AddString(strTime);
if (GetFileTime(hHtml, &lpCreationTime1, &lpLastAccessTime1, &lpLastWriteTime1))
{

FileTimeToLocalFileTime(&lpCreationTime1, &ftime1); // 转换成本地时间
FileTimeToSystemTime(&ftime1, &stime1); // 转换成系统时间格式
}
CloseHandle(hHtml);
strTime.Format("文件夹时间属性-%4d-%2d-%2d-%2d-%2d-%2d",stime1.wYear,
stime1.wMonth,stime1.wDay,stime1.wHour,stime1.wMinute,stime1.wSecond);
DentistryDoctor 2004-11-22
  • 打赏
  • 举报
回复
API函数:SetFileTime.
DentistryDoctor 2004-11-22
  • 打赏
  • 举报
回复
CString szFileName;
GetDlgItemText(IDC_EDIT_FILENAME,szFileName);
HANDLE hFile = CreateFile(szFileName,GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
if(NULL!=hFile)
{
MessageBox(szFileName,"Open file successful!");
SYSTEMTIME st;
FILETIME ft;
FILETIME today;
(reinterpret_cast<CMonthCalCtrl*>(GetDlgItem(IDC_FILETIME)))->GetToday(&st);
st.wHour=0;
SystemTimeToFileTime(&st,&today);
(reinterpret_cast<CMonthCalCtrl*>(GetDlgItem(IDC_FILETIME)))->GetCurSel(&st);
if(SystemTimeToFileTime(&st,&ft))
{
MessageBox("设置时间成功","系统提示信息");
SetFileTime(hFile,&today,&today,&ft);
}
CloseHandle(hFile);
}
BoweirrKing 2004-11-22
  • 打赏
  • 举报
回复
thx,我看看去。
BoweirrKing 2004-11-22
  • 打赏
  • 举报
回复
up ! one time

16,548

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧