用找到所有的.JPG文件,然后删除就行了 virtual BOOL FindFile( LPCTSTR pstrName = NULL, DWORD dwUnused = 0 ); Parameters pstrName A pointer to a string containing the name of the file to find. If you pass NULL for pstrName, FindFile does a wildcard (*.*) search. dwUnused Reserved to make FindFile polymorphic with derived classes. Must be 0. Return Value Nonzero if successful; otherwise 0. To get extended error information, call the Win32 function GetLastError.BOOL DeleteFile( LPCTSTR lpFileName ); Parameters lpFileName [in] Pointer to a null-terminated string that specifies the file or database volume to be deleted. Return ValuesNonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError
virtual BOOL FindFile(
LPCTSTR pstrName = NULL,
DWORD dwUnused = 0
);
Parameters
pstrName
A pointer to a string containing the name of the file to find. If you pass NULL for pstrName, FindFile does a wildcard (*.*) search.
dwUnused
Reserved to make FindFile polymorphic with derived classes. Must be 0.
Return Value
Nonzero if successful; otherwise 0. To get extended error information, call the Win32 function GetLastError.BOOL DeleteFile(
LPCTSTR lpFileName );
Parameters lpFileName
[in] Pointer to a null-terminated string that specifies the file or database volume to be deleted.
Return ValuesNonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError
FindNextFile()对文件夹递归
记得还有所有的 *.avi/*.rm/*.mpg/*.dat
都要删掉哦~~~~~~~~~~~
:))))))))))
CString strWildcard(pstr);
strWildcard += _T("\\*.jpg"); BOOL bWorking = finder.FindFile(strWildcard); while (bWorking)
{
bWorking = finder.FindNextFile();
if (finder.IsDots())
continue;
if (finder.IsDirectory())
{
continue;
}
DeleteFile(finder.GetFilePath());
} finder.Close();
_chdir(Dir);
handle = _findfirst("*", &filestruct);
if(handle == -1)
// ("文件夹为空!")
{
_rmdir(Dir);
}
else//删除所有文件
{
do
{
CString FileName;
FileName.Format("%s",filestruct.name);
if(FileName=="."||FileName=="..")//如果为当前目录或是父目录,继续
continue;
TRY
{
CFile::Remove(FileName);
}
CATCH( CFileException, e )
{
#ifdef _DEBUG
afxDump << "File " << FileName << " cannot be removed\n";
#endif
}
END_CATCH
}
while(!(_findnext(handle,&filestruct)));
_findclose(handle);
_chdir("..");
_rmdir(Dir);
}