C++设置文件属性隐藏文件
| 1.WinExec函数。 |
| 02 | CString strFileName = "c:\1.txt"; |
| 03 | CString strCmd = "attrib +h" + strFileName; |
| 04 | WinExec(strCmd,0); |
| 05 | attrib修改文件属性,+h表示给文件加上隐藏属性。 |
| 06 | 2.SetFileAttributes函数 |
| 07 | BOOL SetFileAttributes(LPCTSTR lpFileName, //file name |
| 08 | WORD dwFileAttributes //file attribute |
| 09 |
| 10 | ); |
| 11 |
| 12 | SetFileAttributes(strFileName,FILE_ATTRIBUTE_HIDDEN); |
| 13 | FILE_ATTRIBUTE_HIDDEN就表示隐藏属性。 |
| 14 | 3.CFile和CFileStatus类 |
| 15 | CFile的静态函数GetStatus可以读取文件状态 |
| 16 | CFile的静态函数SetStatus可以修改文件状态 |
| 17 | FileStatus fs; |
| 18 | CFile::GetStatus(strFileName,fs); |
| 19 | fs.m_attribute = CFile::hidden; //set hidden attribute |
| 20 | CFile::SetStatus(strFileName,fs); |