其实,CFile的GetStatus函数可以解决你的问题 详细情况见 MSDNCFile::GetStatus BOOL GetStatus( CFileStatus& rStatus ) const;static BOOL PASCAL GetStatus( LPCTSTR lpszFileName, CFileStatus& rStatus );Return ValueTRUE if the status information for the specified file is successfully obtained; otherwise, FALSE. ParametersrStatusA 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. lpszFileNameA string in the Windows character set that is the path to the desired file. The path can be relative or absolute, but cannot contain a network name.ResThe virtual version of GetStatus retrieves the status of the open file associated with this CFile object. It does not insert a value into the m_szFullName structure member.The static version gets the status of the named file and copies the filename to m_szFullName. This function obtains the file status from the directory entry without actually opening the file. It is useful for testing the existence and access rights of a file.The m_attribute is the file attribute. The Microsoft Foundation classes provide an enum type attribute so that you can specify attributes symbolically:enum Attribute { normal = 0x00, readOnly = 0x01, hidden = 0x02, system = 0x04, volume = 0x08, directory = 0x10, archive = 0x20 };Example//example for CFile::GetStatus 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 }
DWORD dwFileAttributes; //文件属性
FILETIME ftCreationTime; // 文件创建时间
FILETIME ftLastAccessTime; // 文件最后一次访问时间
FILETIME ftLastWriteTime; // 文件最后一次修改时间
DWORD nFileSizeHigh; // 文件长度高32位
DWORD nFileSizeLow; // 文件长度低32位
DWORD dwReserved0; // 系统保留
DWORD dwReserved1; // 系统保留
TCHAR cFileName[ MAX_PATH ]; // 长文件名
TCHAR cAlternateFileName[ 14 ]; // 8.3格式文件名
} WIN32_FIND_DATA, *PWIN32_FIND_DATA; 可以通过FindFirstFile()函数根据当前的文件存放路径查找该文件来把待操作文件的相关属性读取到WIN32_FIND_DATA结构中去:WIN32_FIND_DATA ffd ;
HANDLE hFind = FindFirstFile("c:\\test.dat",&ffd); 在使用这个结构时不能手工修改这个结构中的任何数据,结构对于开发人员来说只能作为一个只读数据,其所有的成员变量都会由系统完成填写。在MSDN帮助中可以查找到关于WIN32_FIND_DATA结构的更加详细的说明。以上版权归原作者所有
具体看原作者的文章
在VC++下对文件属性的获取与更改http://www.yesky.com/20020904/1628566.shtml
详细情况见 MSDNCFile::GetStatus
BOOL GetStatus( CFileStatus& rStatus ) const;static BOOL PASCAL GetStatus( LPCTSTR lpszFileName, CFileStatus& rStatus );Return ValueTRUE if the status information for the specified file is successfully obtained; otherwise, FALSE. ParametersrStatusA 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.
lpszFileNameA string in the Windows character set that is the path to the desired file. The path can be relative or absolute, but cannot contain a network name.ResThe virtual version of GetStatus retrieves the status of the open file associated with this CFile object. It does not insert a value into the m_szFullName structure member.The static version gets the status of the named file and copies the filename to m_szFullName. This function obtains the file status from the directory entry without actually opening the file. It is useful for testing the existence and access rights of a file.The m_attribute is the file attribute. The Microsoft Foundation classes provide an enum type attribute so that you can specify attributes symbolically:enum Attribute {
normal = 0x00,
readOnly = 0x01,
hidden = 0x02,
system = 0x04,
volume = 0x08,
directory = 0x10,
archive = 0x20
};Example//example for CFile::GetStatus
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
}
CString m_filename;
if(CFile::GetStatus(m_filename,rStatus))
{
// 存在 }
CFileStatus rStatus;
CString m_filename;
if(CFile::GetStatus(m_filename,rStatus))
{
// 存在 }但是在rStatus.m_mtime中是一串怪怪的数字阿
你可以用
CTime 类的 format把它格式化!CTime time = CTime::GetCurrentTime(); ///构造CTime对象
CString str_filetime;
time1=rStatus.m_mtime;
str_filetime=time.Format("%Y-%m-%d %H:%M:%S");