The GetFileSize function retrieves the size, in bytes, of the specified file. DWORD GetFileSize( HANDLE hFile, // handle of file to get size of LPDWORD lpFileSizeHigh // address of high-order word for file size ); 遍历目录,file1.size+file2.size+...+filen.size 可以吗
请问 howtotell(从何谈起) 你的IsStop和IsExe是什么?
DWORD m_dwSize; long count;CString GetSpecialDirectory(CString strGet) { CFileFind finder;
// build a string with wildcards CString strWildcard(strGet); CString strGetInfo; strWildcard += _T("\\*.*");
// start working for files BOOL bWorking = finder.FindFile(strWildcard);
while (bWorking) { bWorking = finder.FindNextFile();
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_INVOKEIDLIST ;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = "properties";
ShExecInfo.lpFile = "c:\\test";
ShExecInfo.lpParameters = "";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
http://search.csdn.net/Expert/topic/1048/1048808.xml?temp=1.992434E-02
当然,遍历时,需要考虑效率,例如使用线程等
void CFindVirus::FindFilesInDirectory(const CString directory)
{
if(IsStop)
{
return;
}
WIN32_FIND_DATA filedata;
HANDLE filehandle;
filehandle=FindFirstFile(directory+"*.*",&filedata);
if(filehandle!=INVALID_HANDLE_VALUE)
{
do
{
if(IsExe(filedata.cFileName))
{
fsize+=filedata.nFileSizeLow;
}
}while(FindNextFile(filehandle,&filedata));
FindClose(filehandle);
}
filehandle=FindFirstFile(directory+"*.*",&filedata);
if(filehandle!=INVALID_HANDLE_VALUE)
{
do
{
if((filedata.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)!=0
&&CString(filedata.cFileName)!="."
&&CString(filedata.cFileName)!="..")
{
FindFilesInDirectory(directory+filedata.cFileName+"\\");
}
}while(FindNextFile(filehandle,&filedata));
FindClose(filehandle);
}
}
LPDWORD lpFileSizeHigh // address of high-order word for file size
);
遍历目录,file1.size+file2.size+...+filen.size
可以吗
你的IsStop和IsExe是什么?
long count;CString GetSpecialDirectory(CString strGet)
{
CFileFind finder;
// build a string with wildcards
CString strWildcard(strGet);
CString strGetInfo;
strWildcard += _T("\\*.*");
// start working for files
BOOL bWorking = finder.FindFile(strWildcard);
while (bWorking)
{
bWorking = finder.FindNextFile();
// skip . and .. files; otherwise, we'd
// recur infinitely!
if (finder.IsDots())
continue;
if(!finder.IsDirectory())
{
m_dwSize = m_dwSize + finder.GetLength();
count ++;
}
// if it's a directory, recursively search it
if (finder.IsDirectory())
{
CString str = finder.GetFilePath();
//cout << (LPCTSTR) str << endl;
CString str1 = GetSpecialDirectory(str);
}
}
strGetInfo.Format(_T("文件个数:%ld 个, 文件夹大小:%ld 字节"),count,m_dwSize);
//AfxMessageBox(strGetInfo);
finder.Close();
return strGetInfo;
} BROWSEINFO bi;
TCHAR szDir[MAX_PATH];
CString strInfoFile;
LPITEMIDLIST pidl;
LPMALLOC pMalloc;
if (SUCCEEDED(SHGetMalloc(&pMalloc)))
{
ZeroMemory(&bi, sizeof(bi));
bi.hwndOwner = this->m_hWnd;
bi.pszDisplayName = 0;
bi.pidlRoot = 0;
bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_VALIDATE ;
pidl = SHBrowseForFolder(&bi);
if (pidl)
{
if (SHGetPathFromIDList(pidl,szDir))
{
SetDlgItemText(IDC_STATIC,szDir);
}
else
{
//m_strDirectory = _T("c:\\")
}
// In C++: pMalloc->Free(pidl); pMalloc->Release();
pMalloc->Free(pidl);
pMalloc->Release();
}
} if(lstrlen(szDir)<=0)
{
return;
}
strInfoFile = GetSpecialDirectory(szDir);
AfxMessageBox(strInfoFile);
{
DWORD fsize=0;
WIN32_FIND_DATA filedata;
HANDLE filehandle;
filehandle=FindFirstFile(ps_Dir + _T("\\*.*"), &filedata);
if(filehandle!=INVALID_HANDLE_VALUE)
{
do
{
fsize += filedata.nFileSizeLow;
}while(FindNextFile(filehandle, &filedata));
FindClose(filehandle);
} return fsize;
}
main()
{
CString ls_test = _T("d:\\test");
DOWRD ld_size = GetDirSize(ls_Test);
}