【MFC】VC调用WinRar解压文件(如:.gz)
2013-04-27 17:36
381 查看
void UnpackFile(const CString & strFilePath) { CString winRarInstallPath = "C:\\Program Files\\WinRAR\\WinRAR.exe"; CString strDestPath; //目标解压位置 int pos = strFilePath.ReverseFind('.'); strDestPath = strFilePath.Left(pos); //删除同名文件 if(::PathFileExists(strDestPath)); { DeleteFile(strDestPath); } // 清空文件 DeleteDirectories(strDestPath); //上篇文章中的函数 if (FALSE == ::CreateDirectory(strDestPath,NULL)) { AfxMessageBox("创建解压路径失败"); return; } //x解压 -ibck后台执行 -o+如存在,则覆盖 -inul不弹出错误提示 //使用 -ibck,缩小到了系统托盘区域 CString strCmd= "\"" + winRarInstallPath + "\" x -ibck -o+ -inul \"" + strFilePath + "\" \"" + strDestPath+"\""; STARTUPINFO si={sizeof(si)}; PROCESS_INFORMATION pi; BOOL bRet=CreateProcess(NULL,strCmd.GetBuffer(MAX_PATH),NULL,NULL,FALSE,0,NULL,NULL,&si,&pi); DWORD dwExit=0; if(bRet) { //这个地方将导致该函数为阻塞状态 WaitForSingleObject(pi.hProcess,INFINITE); ::GetExitCodeProcess(pi.hProcess,&dwExit); CloseHandle(pi.hThread); CloseHandle(pi.hProcess); } return; }
需注意问题:
1.网上有说目标文件路径需要加一个“\“,可能调系统的函数的话是对的,但如果你是拷贝的winrar.exe的话,就不能加"\",不然是无法解压的。
2.调用winrar.exe 而不是rar.exe的原因,这样winrar可以托盘到通知区域,而rar.exe会出现黑窗口,用户体验不好
相关文章推荐
- 利用VC调用WinRAR解压和压缩文件
- 利用VC调用WinRAR解压和压缩文件
- SSIS基本应用--进程任务(调用WinRar解压文件)
- c#调用WinRAR软件压缩和解压文件
- java调用winrar解压文件[rar.bz2.zip.....]
- c# 调用 WinRAR 实现文件压缩、文件解压,WinRAR命令行参数,不弹窗
- 调用WinRAR解压文件
- VC调用WinRAR压缩文件
- C++调用WinRAR压缩解压文件
- VC调用.dll文件
- 如何用命令行生成WinRAR自解压文件
- 7z格式多卷压缩文件使用winRAR解压…
- vs2005MFC中调用海量智能分词研究版.dll文件
- GZIP .gz 文件解压与压缩工具类
- tar.gz文件命名及压缩解压方法
- VC/MFC中通过CWebPage类调用javascript函数(给js函数传参,并取得返回值)
- VC ++ MFC打开文件对话框
- 批处理命令调用WINRAR对文件进行压缩
- 用VC解压缩文件(WinRAR)
- linux下 tar解压 gz解压 bz2等各种解压文件使用方法