MFC common Operations

Source: Internet
Author: User

Directory:

1. File operation

1.1. Get File Size

2. Path operation

2.1. Create a Multilevel Catalog

1. File operation

1.1. Get File Size

// Get File Size  0;        // File Size cfilestatus Filestatus; if (CFile::GetStatus (Csfullfile, Filestatus)) {    = filestatus.m_size;}

Code annotations:

①ulonglong: actually represents integer data (typedef unsigned long long ulonglong;)

②cfilestatus: A structure variable that records the file information, the creation time of the record file, the modified time, the last access time, the file size (in bytes), the file attributes, the file absolute path and other information [1]

structcfilestatus{CTime m_ctime; //creation date/time of fileCTime M_mtime;//Last modification Date/time of fileCTime M_atime;//Last access date/time of fileULONGLONG M_size;//logical size of file in bytesBYTE M_attribute;//logical OR of Cfile::attribute enum valuesBYTE _m_padding;//PAD The structure to a WORDTCHAR M_szfullname[_max_path];//Absolute path name#ifdef _DEBUGvoidDump (cdumpcontext& DC)Const;#endif};

The CTime is a time class that can get time through its member functions getyear (), GetMonth (), GetDay (), Gethour (), Getminute (), Getsecond ().

2. Path operation

2.1. Create a Multilevel Catalog

//function: Create a multilevel directoryBOOLCreatemultidirectory (cstring&Csfullpath) {    //determine if a path exists    if(Pathisdirectory (Csfullpath)) {return true; }    intIPos = Csfullpath.reversefind ('\\'); CString Csformerpath=Csfullpath.left (IPos); if(!pathisdirectory (Csformerpath))    {createmultidirectory (Csformerpath);    } createdirectory (Csfullpath, NULL); //Create Path    return true;}

Code annotations:

① because CreateDirectory () can only create a directory, so to achieve the creation of a multilevel directory, the use of a recursive method

②pathisdirectory () Determine if the path is a valid path, and a similar function pathfileexists () to determine if the path exists, use the header file Shlwapi.h[2]

③reversefind () is a member function of the string class CString to find the first occurrence of a specified character (string) in reverse (right to left)

④left () is also a member function of the string class CString to intercept strings starting from a string (position 0) to a specified character

Note:

[1] cfilestatus structure in the _m_padding is still uncertain meaning

[2] Blog reference: Windows path Operations API functions

MFC common Operations

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.