⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_53095.htm

📁 vc
💻 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&amp; rStatus ) const;<BR><BR>static BOOL PASCAL GetStatus( LPCTSTR lpszFileName, CFileStatus&amp; 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&nbsp;&nbsp; The date and time the file was created.<BR><BR><BR>CTime m_mtime&nbsp;&nbsp; The date and time the file was last modified.<BR><BR><BR>CTime m_atime&nbsp;&nbsp; The date and time the file was last accessed for reading.<BR><BR><BR>LONG m_size&nbsp;&nbsp; The logical size of the file in bytes, as reported by the DIR command.<BR><BR><BR>BYTE m_attribute&nbsp;&nbsp; The attribute byte of the file.<BR><BR><BR>char m_szFullName[_MAX_PATH]&nbsp;&nbsp; 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>&nbsp;&nbsp; normal =&nbsp;&nbsp;&nbsp;&nbsp;0x00,<BR>&nbsp;&nbsp; readOnly =&nbsp;&nbsp;0x01,<BR>&nbsp;&nbsp; hidden =&nbsp;&nbsp;&nbsp;&nbsp;0x02,<BR>&nbsp;&nbsp; system =&nbsp;&nbsp;&nbsp;&nbsp;0x04,<BR>&nbsp;&nbsp; volume =&nbsp;&nbsp;&nbsp;&nbsp;0x08,<BR>&nbsp;&nbsp; directory = 0x10,<BR>&nbsp;&nbsp; archive =&nbsp;&nbsp; 0x20<BR>&nbsp;&nbsp; };<BR><BR>Example<BR><BR>//example for CFile::GetStatus<BR>CFileStatus status;<BR>extern CFile cfile;<BR>if( cfile.GetStatus( status ) )&nbsp;&nbsp;&nbsp;&nbsp;// virtual member function<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#ifdef _DEBUG<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; afxDump &lt;&lt; &#34;File size = &#34; &lt;&lt; status.m_size &lt;&lt; &#34;\n&#34;;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#endif<BR>&nbsp;&nbsp; }<BR>char* pFileName = &#34;test.dat&#34;;<BR>if( CFile::GetStatus( pFileName, status ) )&nbsp;&nbsp; // static function<BR>&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#ifdef _DEBUG<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; afxDump &lt;&lt; &#34;Full file name = &#34; &lt;&lt; status.m_szFullName &lt;&lt; &#34;\n&#34;;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#endif<BR>&nbsp;&nbsp; }<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&amp; 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&nbsp;&nbsp; The date and time the file was created.<BR><BR><BR>CTime m_mtime&nbsp;&nbsp; The date and time the file was last modified.<BR><BR><BR>CTime m_atime&nbsp;&nbsp; The date and time the file was last accessed for reading.<BR><BR><BR>LONG m_size&nbsp;&nbsp; The logical size of the file in bytes, as reported by the DIR command.<BR><BR><BR>BYTE m_attribute&nbsp;&nbsp; The attribute byte of the file.<BR><BR><BR>char m_szFullName[_MAX_PATH]&nbsp;&nbsp; The absolute filename in the Windows character set. <BR><BR><BR>其中enum Attribute {<BR>&nbsp;&nbsp; normal =&nbsp;&nbsp;&nbsp;&nbsp;0x00,<BR>&nbsp;&nbsp; readOnly =&nbsp;&nbsp;0x01,<BR>&nbsp;&nbsp; hidden =&nbsp;&nbsp;&nbsp;&nbsp;0x02,<BR>&nbsp;&nbsp; system =&nbsp;&nbsp;&nbsp;&nbsp;0x04,<BR>&nbsp;&nbsp; volume =&nbsp;&nbsp;&nbsp;&nbsp;0x08,<BR>&nbsp;&nbsp; directory = 0x10,<BR>&nbsp;&nbsp; archive =&nbsp;&nbsp; 0x20<BR>&nbsp;&nbsp; };<BR><BR>设置的话:<BR>static void CFile::SetStatus( LPCTSTR lpszFileName, const CFileStatus&amp; 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 + -