这个是一个很简单的修改文件时间的程序,对创建进间,修改时间,访问时间可以任意的修改,相当有意思!这段代码仅修改了创建时间,没能什么技术含量只是觉得好玩!
CFileDialog fileDlg(true);
fileDlg.DoModal( );
CString tempstr;
tempstr=fileDlg.GetPathName();
this->UpdateData ();
int state=0;
state=this->m_createcheck .GetCheck ();
if (state==1)
{
SYSTEMTIME st;
st.wYear =this->m_time1.GetYear ();
st.wDay =this->m_time1 .GetDay ();
st.wDayOfWeek =this->m_time1.GetDayOfWeek ();
st.wHour =this->m_time1 .GetHour ();
st.wMinute =this->m_time1 .GetMinute ();
st.wSecond =this->m_time1 .GetSecond ();
st.wMilliseconds =this->m_time1 .GetSecond ();
st.wMonth =this->m_time1 .GetMonth ();
FILETIME ft;
::SystemTimeToFileTime (&st,&ft);
HANDLE hFile;
hFile=::CreateFile (tempstr,GENERIC_WRITE|GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,NULL);
if (INVALID_HANDLE_VALUE==hFile)
{
this->MessageBox("修改文件创建时间失败","信息");
::CloseHandle (hFile);
}
else
{
bool m_file;
m_file=::SetFileTime (hFile,&ft,NULL,NULL);
if (m_file==true)
{
this->MessageBox("修改文件创建时间成功","信息");
}
else
{
this->MessageBox("修改文件创建时间失败","信息");
}
::CloseHandle (hFile);
}
}
state=this->m_modifycheck .GetCheck ();
if (state==1)
{
SYSTEMTIME st;
st.wYear =this->m_time2.GetYear ();
st.wDay =this->m_time2 .GetDay ();
st.wDayOfWeek =this->m_time2.GetDayOfWeek ();
st.wHour =this->m_time2 .GetHour ();
st.wMinute =this->m_time2 .GetMinute ();
st.wSecond =this->m_time2 .GetSecond ();
st.wMilliseconds =this->m_time2 .GetSecond ();
st.wMonth =this->m_time2 .GetMonth ();
FILETIME ft;
::SystemTimeToFileTime (&st,&ft);
HANDLE hFile;
hFile=::CreateFile (tempstr,GENERIC_WRITE|GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,NULL);
if (INVALID_HANDLE_VALUE==hFile)
{
this->MessageBox("修改文件修改时间失败","信息");
::CloseHandle (hFile);
}
else
{
bool m_file;
m_file=::SetFileTime (hFile,NULL,&ft,NULL);
if (m_file==true)
{
this->MessageBox("修改文件修改时间成功","信息");
}
else
{
this->MessageBox("修改文件修改时间失败","信息");
}
::CloseHandle (hFile);
}
}
state=this->m_visitcheck .GetCheck ();
if (state==1)
{
SYSTEMTIME st;
st.wYear =this->m_time3.GetYear ();
st.wDay =this->m_time3 .GetDay ();
st.wDayOfWeek =this->m_time3.GetDayOfWeek ();
st.wHour =this->m_time3 .GetHour ();
st.wMinute =this->m_time3 .GetMinute ();
st.wSecond =this->m_time3.GetSecond ();
st.wMilliseconds =this->m_time3 .GetSecond ();
st.wMonth =this->m_time3 .GetMonth ();
FILETIME ft;
::SystemTimeToFileTime (&st,&ft);
HANDLE hFile;
hFile=::CreateFile (tempstr,GENERIC_WRITE|GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,NULL);
if (INVALID_HANDLE_VALUE==hFile)
{
this->MessageBox("修改文件访问时间失败","信息");
::CloseHandle (hFile);
}
else
{
bool m_file;
m_file=::SetFileTime (hFile,NULL,NULL,&ft);
if (m_file==true)
{
this->MessageBox("修改文件访问时间成功","信息");
}
else
{
this->MessageBox("修改文件访问时间失败","信息");
}
::CloseHandle (hFile);
}
}