1. Hide files.
1. winexec function.
This function executes a cmd command, such as modifying
C: // Documents and Settings // emlab // Application Data // test.txt
The file property can be hidden:
Cstring strfilename =
"C: // Documents and Settings // emlab // Application Data // test.txt ";
Cstring strcmd = "attrib + H" + strfilename;
Winexec (strcmd, 0 );
Attrib modifies the file attributes. + H indicates adding hidden attributes to the file.
2. setfileattributes Function
Prototype: bool setfileattributes (lpctstr lpfilename, // file name
Word dwfileattributes // File Attribute
);
For example:
Setfileattributes (strfilename, file_attribute_hidden );
File_attribute_hidden indicates that the property is hidden.
3. cfile and cfilestatus
The cfile static function getstatus can read the file status.
The cfile static function setstatus can modify the File status.
For example:
Filestatus FS;
Cfile: getstatus (strfilename, FS );
FS. m_attribute = cfile: hidden; // set hidden attribute
Cfile: setstatus (strfilename, FS );
Ii. Determine whether a file exists.
1. _ access function, in Io. h.
Prototype: int _ access (const char * filename, int amode );
Parameter amode (as if there are 5 Modes)
0: Check whether the file exists
1: Check whether the file is running
2: Check whether the file is writable.
4: Check whether the file is readable.
There is another kind, because msdn suddenly breaks down and is retained for the moment
If (_ access (file, 0 ))
{
// The file does not exist.
}
2. cfile and cfilestatus
Cfile static function getstatus. If false is returned, the file does not exist.
Cfilestatus FS;
If (! Cfile: getstatus (strfilename, FS ))
{
// The file does not exist.
}
3. cfilefind class
Use findfile, a member function of this class, to determine
Cfilefind ff;
If (! Ff. findfile (strfilename ))
{
// The file does not exist.
}
Ff. Close ();
3. Determine whether a folder exists
Direxists (Spath );
3. delete an object
Cfile tempfile;
Tempfile. Remove (specify the file name );
//////////////////////////////////////// ////////////////
_ Rmdir (): Delete the directory.
//////////////////////////////////////// ////////////////
Deletefile () delete an object
//////////////////////////////////////// ////////////////
If (: deletefile ("C: // autoexec. Bat "))
Afxmessagebox ("File deleted successfully ");
Deletefile is defined in windows. h and WINBASE. h.