1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
| void CMyComputerDlg::ShowFileInfo(CString filePath,int i) { FILEINFO* fileInfo = new FILEINFO; CString buf; if (wcscmp(L".sLn", PathFindExtension(filePath)) == 0 || wcscmp(L".obj", PathFindExtension(filePath)) == 0 || wcscmp(L".tlog", PathFindExtension(filePath)) == 0 || wcscmp(L".idb", PathFindExtension(filePath)) == 0 || wcscmp(L".pdb", PathFindExtension(filePath)) == 0 || wcscmp(L".pch", PathFindExtension(filePath)) == 0 || wcscmp(L".res", PathFindExtension(filePath)) == 0 || wcscmp(L".ilk", PathFindExtension(filePath)) == 0 || wcscmp(L".sdf", PathFindExtension(filePath)) == 0 || wcscmp(L".ipch", PathFindExtension(filePath)) == 0 || wcscmp(L".lastbuildstate", PathFindExtension(filePath)) == 0 ) { buf.Format(L"VS工程文件"); m_objComList.SetItemText(i, 1, buf); fileInfo->TYPE = buf; } else if (wcscmp(L".cpp", PathFindExtension(filePath)) == 0 || wcscmp(L".h", PathFindExtension(filePath)) == 0 ) { buf.Format(L"C++代码"); m_objComList.SetItemText(i, 1, buf); fileInfo->TYPE = buf; } else if (wcscmp(L".exe", PathFindExtension(filePath)) == 0 ) { buf.Format(L"应用程序"); m_objComList.SetItemText(i, 1, buf); fileInfo->TYPE = buf; } else if ( wcscmp(L".dll", PathFindExtension(filePath)) == 0 ) { buf.Format(L"应用程序扩展"); m_objComList.SetItemText(i, 1, buf); fileInfo->TYPE = buf; } else if (wcscmp(L".msi", PathFindExtension(filePath)) == 0
) { buf.Format(L"Windows安装程序包"); m_objComList.SetItemText(i, 1, buf); fileInfo->TYPE = buf; } else if (wcscmp(L".html", PathFindExtension(filePath)) == 0|| wcscmp(L".js", PathFindExtension(filePath)) == 0 || wcscmp(L".css", PathFindExtension(filePath)) == 0 || wcscmp(L".htm", PathFindExtension(filePath)) == 0 ) { buf.Format(L"网页文件"); m_objComList.SetItemText(i, 1, buf); fileInfo->TYPE = buf; } else if ( wcscmp(L".rar", PathFindExtension(filePath)) == 0|| wcscmp(L".7z", PathFindExtension(filePath)) == 0 || wcscmp(L".zip", PathFindExtension(filePath)) == 0 ) { buf.Format(L"压缩文件"); m_objComList.SetItemText(i, 1, buf); fileInfo->TYPE = buf; } else if ( wcscmp(L".log", PathFindExtension(filePath)) == 0 ) { buf.Format(L"日志文件"); m_objComList.SetItemText(i, 1, buf); fileInfo->TYPE = buf; } else { CString cs; cs = filePath; buf= cs.Right(3); cs.Format(L"%s文件",buf); m_objComList.SetItemText(i, 1, cs); fileInfo->TYPE = buf; } HANDLE hFile = CreateFile(filePath, GENERIC_READ | GENERIC_WRITE, NULL, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); CHAR Buffer[10] = { 0 }; DWORD Read = 0; ReadFile(hFile, Buffer, 3, &Read, NULL); CString cs; DWORD dwRealSize = 0; if (hFile != INVALID_HANDLE_VALUE) {
DWORD dwSize = GetFileSize(hFile, NULL); dwRealSize = dwSize; CloseHandle(hFile); }
DWORD dwAttribute = GetFileAttributes(filePath); if (dwAttribute & FILE_ATTRIBUTE_HIDDEN) {
buf.Format(L"隐藏文件"); m_objComList.SetItemText(i, 4, buf); fileInfo->PROPERTY = buf; } if (dwAttribute & FILE_ATTRIBUTE_READONLY) { buf.Format(L"只读文件"); m_objComList.SetItemText(i, 4, buf); fileInfo->PROPERTY = buf; } WIN32_FILE_ATTRIBUTE_DATA wfad = {};
GetFileAttributesEx(filePath, GetFileExInfoStandard, &wfad); FILETIME fi = { 0 }; SYSTEMTIME st = { 0 }; FILETIME fix = { 0 }; SYSTEMTIME stx = { 0 }; FILETIME fiw = { 0 }; SYSTEMTIME stw = { 0 }; FileTimeToLocalFileTime(&wfad.ftCreationTime, &fi); FileTimeToLocalFileTime(&wfad.ftLastAccessTime, &fix); FileTimeToLocalFileTime(&wfad.ftLastAccessTime, &fiw); FileTimeToSystemTime(&fi, &st); FileTimeToSystemTime(&fix, &stx); FileTimeToSystemTime(&fiw, &stw);
buf.Format(L"%d年%d月%d日-%d时%d分%d秒", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond); fileInfo->CREATEDATE = buf; buf.Format(L"%d年%d月%d日-%d时%d分%d秒", stx.wYear, stx.wMonth, stx.wDay, stx.wHour, stx.wMinute, stx.wSecond); m_objComList.SetItemText(i, 3, buf); fileInfo->MODIFYDATE = buf; buf.Format(L"%d年%d月%d日-%d时%d分%d秒", stw.wYear, stw.wMonth, stw.wDay, stw.wHour, stw.wMinute, stw.wSecond); fileInfo->ACCESSDATE = buf;
CString csSize; int Size = dwRealSize / 1024; if (Size < 1) { csSize.Format(L"1 Kb"); m_objComList.SetItemText(i, 2, csSize); fileInfo->SIZE = Size; } else if((Size/1024)) {
csSize.Format(L"%d Kb", Size); m_objComList.SetItemText(i, 2, csSize); fileInfo->SIZE = Size; } m_objComList.SetItemText(i,5, filePath); fileInfo->PATH = filePath; vecFileInfo.push_back(fileInfo); }
|