Cpp_01
asked on
how to get the time stamp of a file or folder?
In C++,how to get the time stamp of the File?That is how to know if the file has been modified with compare to old file.
What OS?
For Windows, you can use the following C Run Time library functions.
_fstat, _fstati64
_stat, _wstat, _stati64, _wstati64
Or, the following API functions.
GetFileTime
GetFileInformationByHandle
For Windows, you can use the following C Run Time library functions.
_fstat, _fstati64
_stat, _wstat, _stati64, _wstati64
Or, the following API functions.
GetFileTime
GetFileInformationByHandle
If you are using MFC...
CString sTifFileDateTime;
CFileStatus status;
try
{
CFile cfile( sFile, CFile::modeRead ); //PUT YOUR FILE NAME HERE
if( cfile.GetStatus( status ) )
{
//get the file's date/time and format it
CString sFileDateTime;
CTime fileTime = status.m_mtime;
sFileDateTime = fileTime.Format( "%Y%m%d%H%M%S0000" );
}
else
{
sError = "Could not get file statistics on file " + sFile;
cout << sError << endl;
return -1;
}
cfile.Close();
}
catch (CFileException *ex )
{
CString sCause;
switch ( ex->m_cause )
{
case CFileException::generic:
sCause = "An unspecified error occurred.";
break;
case CFileException::fileNotFou
sCause = "The file could not be located.";
break;
....
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
or
man fstat