VC file exists File Attribute delete file

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.