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