rt

解决方案 »

  1.   

    WIN32_FIND_DATA结构  关于文件的全部属性信息,总计有以下以下9种:文件的标题名、文件的属性(只读、存档,隐藏等)、文件的创建时间、文件的最后访问时间、文件的最后修改时间、文件大小的高位双字、文件大小的低位双字、保留、保留。在这里只有文件标题名和文件的长度可以通过CFile类比较方便的获得,而对于其他几种属性的获取和设置就无能为力了。  在用findfirst()和findnext()函数去查找磁盘文件时经常使用的一个数据结构WIN32_FIND_DATA的成员变量里包含了以上所有的文件属性,因此可以通过这个结构作为获取和更改文件属性的手段。该结构的内容如下:typedef struct _WIN32_FIND_DATA {
      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
      

  2.   

    其实,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
       }
      

  3.   

    CFileStatus rStatus;
    CString m_filename;
    if(CFile::GetStatus(m_filename,rStatus))
    {
    // 存在 }
      

  4.   

    我用的是
    CFileStatus rStatus;
    CString m_filename;
    if(CFile::GetStatus(m_filename,rStatus))
    {
    // 存在 }但是在rStatus.m_mtime中是一串怪怪的数字阿
      

  5.   

    rStatus.m_mtime 得到的是一个Ctime类型的变量!
    你可以用
    CTime 类的 format把它格式化!CTime time = CTime::GetCurrentTime();   ///构造CTime对象
    CString str_filetime;
    time1=rStatus.m_mtime;
    str_filetime=time.Format("%Y-%m-%d %H:%M:%S");