📄 subject_53095.htm
字号:
<p>
序号:53095 发表者:蝴蝶兰 发表日期:2003-09-17 11:33:33
<br>主题:如何获得一个指定文件的属性
<br>内容:我知道一个文件的路径 ,如何知道这个文件的属性,比如是否是只读,<BR>如何更改文件的只读属性
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:风之文章 回复日期:2003-09-17 11:46:05
<br>内容:CFile::GetStatus <BR>BOOL GetStatus( CFileStatus& rStatus ) const;<BR><BR>static BOOL PASCAL GetStatus( LPCTSTR lpszFileName, CFileStatus& rStatus );<BR><BR>Return Value<BR><BR>TRUE if the status information for the specified file is successfully obtained; otherwise, FALSE. <BR><BR>Parameters<BR><BR>rStatus<BR><BR>A reference to a user-supplied CFileStatus structure that will receive the status information. The CFileStatus structure has the following fields: <BR><BR>CTime m_ctime The date and time the file was created.<BR><BR><BR>CTime m_mtime The date and time the file was last modified.<BR><BR><BR>CTime m_atime The date and time the file was last accessed for reading.<BR><BR><BR>LONG m_size The logical size of the file in bytes, as reported by the DIR command.<BR><BR><BR>BYTE m_attribute The attribute byte of the file.<BR><BR><BR>char m_szFullName[_MAX_PATH] The absolute filename in the Windows character set. <BR>lpszFileName<BR><BR>A 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.<BR><BR>Remarks<BR><BR>The 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.<BR><BR>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.<BR><BR>The m_attribute is the file attribute. The Microsoft Foundation classes provide an enum type attribute so that you can specify attributes symbolically:<BR><BR>enum Attribute {<BR> normal = 0x00,<BR> readOnly = 0x01,<BR> hidden = 0x02,<BR> system = 0x04,<BR> volume = 0x08,<BR> directory = 0x10,<BR> archive = 0x20<BR> };<BR><BR>Example<BR><BR>//example for CFile::GetStatus<BR>CFileStatus status;<BR>extern CFile cfile;<BR>if( cfile.GetStatus( status ) ) // virtual member function<BR> {<BR> #ifdef _DEBUG<BR> afxDump << "File size = " << status.m_size << "\n";<BR> #endif<BR> }<BR>char* pFileName = "test.dat";<BR>if( CFile::GetStatus( pFileName, status ) ) // static function<BR> {<BR> #ifdef _DEBUG<BR> afxDump << "Full file name = " << status.m_szFullName << "\n";<BR> #endif<BR> }<BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:iamhere 回复日期:2003-09-17 11:47:09
<br>内容:获取:<BR>static BOOL PASCAL CFile::GetStatus( LPCTSTR lpszFileName, CFileStatus& rStatus );<BR><BR>其中:<BR>rStatus<BR><BR>A reference to a user-supplied CFileStatus structure that will receive the status information. The CFileStatus structure has the following fields: <BR><BR>CTime m_ctime The date and time the file was created.<BR><BR><BR>CTime m_mtime The date and time the file was last modified.<BR><BR><BR>CTime m_atime The date and time the file was last accessed for reading.<BR><BR><BR>LONG m_size The logical size of the file in bytes, as reported by the DIR command.<BR><BR><BR>BYTE m_attribute The attribute byte of the file.<BR><BR><BR>char m_szFullName[_MAX_PATH] The absolute filename in the Windows character set. <BR><BR><BR>其中enum Attribute {<BR> normal = 0x00,<BR> readOnly = 0x01,<BR> hidden = 0x02,<BR> system = 0x04,<BR> volume = 0x08,<BR> directory = 0x10,<BR> archive = 0x20<BR> };<BR><BR>设置的话:<BR>static void CFile::SetStatus( LPCTSTR lpszFileName, const CFileStatus& status );<BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -