请问有什么办法可以获取文件的最后修改日期和时间,vc,c++的都可以,急!!!!!

leotam 2002-05-23 03:58:42
运行系统为win2000!请大虾不吝赐教!!!!
...全文
311 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
ylb_and_xy 2002-05-23
  • 打赏
  • 举报
回复
BOOL GetFileInformationByHandle(
[in]HANDLE hFile, // handle to file
[out]LPBY_HANDLE_FILE_INFORMATION lpFileInformation // buffer
);

typedef struct _BY_HANDLE_FILE_INFORMATION {
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD dwVolumeSerialNumber;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
DWORD nNumberOfLinks;
DWORD nFileIndexHigh;
DWORD nFileIndexLow;
} BY_HANDLE_FILE_INFORMATION, *PBY_HANDLE_FILE_INFORMATION;

1.ftCreationTime
Specifies the time the file was created. If the underlying file system does not support this time member, ftCreationTime is zero.
2.ftLastAccessTime
Specifies the time the file was last accessed. If the underlying file system does not support this time member, ftLastAccessTime is zero.
3.ftLastWriteTime
Specifies the last time the file was written to.
leotam 2002-05-23
  • 打赏
  • 举报
回复
可是为什么我用 CreateFile后,再用 GetFileTime就不行呢,
code:
HANDLE hFile;
hFile= CreateFile("C:\\Documents and Settings\\tsl\\桌面\联系.txt",GENERIC_READ,FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
BOOL bFile=GetFileTime(hFile,lpCreationTime,lpLastAccessTime,lpLastWriteTime) ;
其实问题已经解决了,只是想知道的说!

十分多谢日月紫光详细解答,还有我心迷茫,雨一直下。。。。。
分明天给,各大虾可否再指点一二!!!
麻烦大家了!


xintiaf 2002-05-23
  • 打赏
  • 举报
回复
刚刚写错了:)
这个调试通过!

void CTestDlg::OnBtnTest()
{
HANDLE hFile;
WIN32_FIND_DATA wfd;
SYSTEMTIME systime;
FILETIME localtime;
char stime[32]; //输出时间
memset(&wfd, 0, sizeof(wfd));

if((hFile=FindFirstFile("F:\\VC\\MFC\\Test\\Release\\Test.exe", &wfd))==INVALID_HANDLE_VALUE)
{
char c[2];
DWORD dw=GetLastError();
wsprintf(c, "%d", dw);
AfxMessageBox(c);
return ;//失败
}
//ok,转换时间
FileTimeToLocalFileTime(&wfd.ftLastWriteTime,&localtime);
FileTimeToSystemTime(&localtime,&systime);
sprintf(stime,"%4d-%02d-%02d %02d:%02d:%02d",
systime.wYear,systime.wMonth,systime.wDay,systime.wHour,
systime.wMinute,systime.wSecond);
AfxMessageBox(stime);
}

xintiaf 2002-05-23
  • 打赏
  • 举报
回复
先将你要找的文件名(包括全路径)给attrib.filename
xintiaf 2002-05-23
  • 打赏
  • 举报
回复
HANDLE hFile;
FILEATTRIB attrib;
WIN32_FIND_DATA WFD;
SYSTEMTIME systime;
FILETIME localtime;
har stime[32]; //输出时间

if((hFile=FindFirstFile(attrib.filename,&WFD))=INVALID_HANDLE_VALUE)
return false;//失败
//ok,转换时间
FileTimeToLocalFileTime(&WFD.ftLastWriteTime,&localtime);
FileTimeToSystemTime(&localtime,&systime);
sprintf(stime,"%4d-%02d-%02d %02d:%02d:%02d",
systime.wYear,systime.wMonth,systime.wDay,systime.wHour,
systime.wMinute,systime.wSecond);
AfxMessageBox(stime);

hyc1980 2002-05-23
  • 打赏
  • 举报
回复
one more powerful shell api

ShGetFileInfo
whz_time 2002-05-23
  • 打赏
  • 举报
回复
用“CFile::GetStatus(LPCTSTR lpszFileName, CFileStatus& rStatus );


rStatus

A reference to a user-supplied CFileStatus structure that will receive the status information. The CFileStatus structure has the following fields:

CTime m_ctime The date and time the file was created.


CTime m_mtime The date and time the file was last modified.


CTime m_atime The date and time the file was last accessed for reading.


LONG m_size The logical size of the file in bytes, as reported by the DIR command.


BYTE m_attribute The attribute byte of the file.


char m_szFullName[_MAX_PATH] The absolute filename in the Windows character set.


Example:

CFileStatus status;
extern CFile cfile;
if( cfile.GetStatus( status ) ) // virtual member function
{
#ifdef _DEBUG
afxDump << "File size = " << status.m_size << "\n";
#endif
}
char* pFileName = "test.dat";
if( CFile::GetStatus( pFileName, status ) ) // static function
{
#ifdef _DEBUG
afxDump << "Full file name = " << status.m_szFullName << "\n";
#endif
}

jaidy 2002-05-23
  • 打赏
  • 举报
回复
BOOL GetFileAttributesEx(
LPCTSTR lpFileName, // file or directory name
GET_FILEEX_INFO_LEVELS fInfoLevelId, // attribute class
LPVOID lpFileInformation // attribute information
);
fInfoLevelId
[in] Specifies the class of attribute information to retrieve. This parameter can be one of the following values.
Value Meaning
GetFileExInfoStandard The lpFileInformation parameter is a
WIN32_FILE_ATTRIBUTE_DATA structure
建议仔细看看msdn
flounder 2002-05-23
  • 打赏
  • 举报
回复
GetFileAttributesEx()
Kevin_qing 2002-05-23
  • 打赏
  • 举报
回复
BOOL GetFileAttributesEx(
LPCTSTR lpFileName, // file or directory name
GET_FILEEX_INFO_LEVELS fInfoLevelId, // attribute
LPVOID lpFileInformation // attribute information
);


的fInfoLevelId参数里面
gameboy999 2002-05-23
  • 打赏
  • 举报
回复
FindFirstFile
FindNextFile
就可以了
1,cccode.zip一个监控别人计算机的程序(65KB)2,cihcn.zipCIH病毒1.4版本之中文注释(25KB)3,regmonsrc.zip监控win9x下文件的读写(251KB)4,quickprt.zip增强的quickrpt(70KB)5,xxm.zip餐桌管理程序(83KB)6,dfbak.zip电费管理程序(981KB)7,pterm01b.zip终端仿真程序(63KB)8,drivevie.zip查看系统安装的驱动器(34KB)9,findprocess.zip列举所有的进程基类(107KB)10,mfctlist.zip列举操作系统中所有的进程,你能够在程序中消灭进程。程序由Visual C++ 5.0开发,工作于Windows 95(98),Windows NT 4.0(28KB)11,CServer.ZIP多线程实现客户-服务器结构的一个例子(37KB)12,splasher.zip用线程实现软件的片头(Splash Screen)(62KB)13,getinfo.zip获取系统硬件信息源代码(39KB)14,getfontinfo.zip获取系统所有字体信息源代码(51KB)15,detectos.zip获取操作系统版本信息源代码(42KB)16,gethostip.zip获得主机名和IP地址(34KB)17,shellext.zip用程序启动IE Outlook Explore(30KB)18,autolog.zipWinNT 自动登录源程序(13KB)19,cpuinfo.zip一个取得 CPU 信息的程序源码(164KB)20,apihook.zipAPI钩子APIHOOK 2.0 源代码(91KB)21,registry.zip查询修改注册表源代码(40KB)22,q1.zip程序创建两个线程,第一个线程没有消息队列,主线程尝试给第一个线程发送一个消息,我们可以看到PostThreadMessage()返回FALSE,程序创建的第二个线程有一个消息队列,主线程中的PostThreadMessage()返回TRUE,程序由Visual C++ 6.0开发,没有用到MFC(79KB)23,pstat.zip在程序需要进行较长时间工作的时候,总希望能有一个进度条告诉我们当前的进度,这个例子利用线程显示进度条值得一看 COOL(20KB)24,m4kit15.zip简单的环境继承(persistence)库(548KB)25,vxdlib11.zip自动生成虚拟设备驱动(VXD)的C++代码的一个库 COOL!(431KB)26,hklm.zipCHKLM类允许你在注册表的HKEY_LOCAL_MACHINE注册键中做写操作(10KB)27,pipe_pro.zip管道类(30KB)28,Storage.zip存储类(9KB)29,dt220.zip日期时间的扩展类2.2版,需要安装(1149KB)30,dt221.zip日期时间的扩展类2.2版的更新程序(22KB)31,DllIco.zip得到DLL/EXE文件中的资源定义 Cool(85KB)32,stealth.zip这个由Visual C++ 5.0开发的SDI程序演示如何让程序运行时在Window 95或Windows NT 4.0的任务条上不显示出来,程序重载了CMainFrame中的PreCreateWindow()函数 COOL(29KB)33,FontsTest.zip列举系统中的所有字体(41KB)34,memmap.zip操作内存映像文件,提供的CMemMapFile功能强大(16KB)35,cfile64.zip支持Win32 64位文件系统的一个类

16,472

社区成员

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

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

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