1 void CGetFileSizeDlg::OnBnClickedButton1() 2 { 3 CString strFile; 4 GetDlgItemText(IDC_EDIT1, strFile); 5 DWORD dwHigh = 0;//(文件大小超过4GB)存放33-64位高位 6 DWORD dwLow = 0;//存放1-32位低位 7 HANDLE hFile = CreateFile(strFile, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 8 if (hFile == INVALID_HANDLE_VALUE) { 9 DWORD errCode = GetLastError(); 10 SzErr CString; . 11 szErr.Format (_T ( " ! Some errors in the CreateFile error code is D% " ), errCode); 12 is the MessageBox (szErr); 13 is the CloseHandle (hFile); 14 return ; 15 } 16 dwLow = the GetFileSize (hFile, & dwHigh); . 17 the LONGLONG Ltotal = ((the LONGLONG) dwHigh << 32 ) | dwLow; // to form the final 8-byte file size LONGLONG (INT64) type number 18 is DOUBLE dbTotal = (DOUBLE) Ltotal; . 19 DOUBLE kbSize = dbTotal / 1024 ; 20 is DOUBLE mbSize dbTotal = / (1024 * 1024 ); 21 is DOUBLE gbSize = dbTotal / ( 1024 * 1024 * 1024 ); 22 is CString the cbSize; 23 is cbSize.Format (_T ( " file size% lld bytes (% 0.2fKB,% 0.2fMB,% 0.2fGB ) " ), Ltotal, kbSize, mbSize, gbSize); 24 the MessageBox (the cbSize); 25 the CloseHandle (hFile); 26 is return ; 27 }
GetFileSize usage (including the use of the format string)
Guess you like
Origin www.cnblogs.com/mktest123/p/12130274.html
Recommended
Ranking