MFC 解压7z文件
flyfish
环境需要7z.exe 和7z.dll
CString GetPath()
{
CString sPath;
TCHAR szDirectory[MAX_PATH] = L"";
::GetCurrentDirectory(sizeof(szDirectory) - 1, szDirectory);
sPath = szDirectory;
return sPath;// 不带 //
}
void Decompression()
{
// TODO: 在此添加控件通知处理程序代码
//解压到当前目录
CString str7zExePath = GetPath() + _T("\\7z.exe");//7z.exe文件所在路径
CString strSourcePath = GetPath() + _T("\\Test.7z");//解压文件的路径
CString strDestinationDir = GetPath();
CString strParameter;//解压参数
strParameter.Format(_T("x %s -o%s -y"), strSourcePath, strDestinationDir); //按照7Z文件的原目录解压
HINSTANCE hRet = ShellExecute(NULL, L"open", str7zExePath, strParameter, NULL, SW_HIDE);
if (!hRet)
{
//失败
}
else
{
//成功
}
//x: eXtract files with full paths
//-o{Directory}: set Output directory
//-y: assume Yes on all queries
}