VB.NET压缩和解压缩实例全面分析
创始人
2024-06-09 06:11:35
0

在我们运用VB.NET这门语言时,我们尝尝会遇到VB.NET压缩和解压缩的问题,如何能更好的实现VB.NET压缩的问题,在这里我们用一个实例给大家详细分析一下,希望可以给大家带来帮助。

VB.NET压缩和解压缩实现代码:

  1. PublicEnumZip  
  2. Zip=0'压缩  
  3. UnZip=1'解压缩  
  4. EndEnum  
  5. '压缩、解压缩  
  6. PublicFunctionZipFile(ByValinDirPathAsString,OptionalByVal_zipAsZip=Zip.Zip,_  
  7. OptionalByValstrFileNameAsString="C:\BACKUP")AsBoolean  
  8. DimInfoAsNewInformation  
  9. DimPrintMessageAsNewErrorinf  
  10. DimstrCommandAsString  
  11. If_zip=Zip.ZipThen  
  12. DimdirectoryEntriesAsString()  
  13. directoryEntries=System.IO.Directory.GetFileSystemEntries(inDirPath)  
  14. DimstrFileAsString,strFileAllAsString  
  15. ForEachstrFileIndirectoryEntries  
  16. strFileAllstrFileAll=strFileAll&"-ep1"&strFile  
  17. Next  
  18. DimstrPassAsString=InputBox(Info.NOR_InputPassword,Info.NOR_PasswordInput)  
  19. IfstrPass.Length>0Then  
  20. strCommand="winrarA-hp"+strPass+"-ep1"  
  21. Else  
  22. strCommand="winrarA-ep1" 
  23. EndIf  
  24. strCommandstrCommand=strCommand&Space(1)&strFileName&Space(1)&strFileAll  
  25. Try  
  26. IfSystem.IO.File.Exists(strFileName)Then  
  27. IfMsgBox(Info.NOR_ReplaceFile,_  
  28. MsgBoxStyle.OKCancel+_  
  29. MsgBoxStyle.Information,Info.NOR_Prompt)=MsgBoxResult.CancelThen  
  30. ReturnFalse  
  31. Else  
  32. Shell(strCommand,AppWinStyle.NormalFocus,True)  
  33. EndIf  
  34. Else  
  35. Shell(strCommand,AppWinStyle.NormalFocus,True)  
  36. EndIf  
  37. MsgBox(Info.SUC_ZipBackSuccess,MsgBoxStyle.OKOnly+MsgBoxStyle.Information,Info.NOR_Prompt)  
  38. ReturnTrue  
  39. Catch  
  40. PrintMessage.WriteErr("Cls_Common->ZipFile",Info.ERR_ZipBackError)  
  41. MsgBox(Info.ERR_ZipBackError,MsgBoxStyle.OKOnly+MsgBoxStyle.Information,Info.NOR_Prompt)  
  42. ReturnFalse  
  43. EndTry  
  44. Else  
  45. DimOpenDialogAsNewOpenFileDialog  
  46. OpenDialog.Filter="还原压缩数据*.rar|*.rar" 
  47. IfOpenDialog.ShowDialog=DialogResult.CancelThen  
  48. OpenDialog.Dispose()  
  49. ReturnFalse  
  50. EndIf  
  51. strFileName=OpenDialog.FileName  
  52. DimstrRePassAsString=InputBox(Info.NOR_InputPassword,Info.NOR_PasswordInput)  
  53. IfstrRePass.Trim.Length>0Then  
  54. strCommand="winrarX-hp"+strRePass.Trim+"-o+-inul-ep2"  
  55. Else  
  56. strCommand="winrarX-o+-inul-ep2" 
  57. EndIf  
  58. strCommandstrCommand=strCommand&Space(1)&strFileName&Space(1)&Application.StartupPath  
  59. OpenDialog.Dispose()  
  60. Try  
  61. Shell(strCommand,AppWinStyle.NormalFocus,True)  
  62. MsgBox(Info.SUC_ZipRevertSuccess,MsgBoxStyle.OKOnly+MsgBoxStyle.Information,Info.NOR_Prompt)  
  63. ReturnTrue  
  64. Catch  
  65. PrintMessage.WriteErr("Cls_Common->ZipFile",Info.ERR_ZipRevertError)  
  66. MsgBox(Info.ERR_ZipRevertError,MsgBoxStyle.OKOnly+MsgBoxStyle.Information,Info.NOR_Prompt)  
  67. ReturnFalse  
  68. EndTry  
  69. EndIf  
  70. 'Debug.Write(strCommand)  
  71. EndFunction 

你的应用程序的bin下要有一个winrar的可执行文件.

【编辑推荐】

  1. 全方位分析VB.NET编码规范
  2. 剖析VB.NET Process的属性与对象
  3. VB.NET SendKeys方法与键入值
  4. 用实例讲述VB.NET Process类
  5. 简单讲述VB.NET表间拖放

相关内容

热门资讯

如何允许远程连接到MySQL数... [[277004]]【51CTO.com快译】默认情况下,MySQL服务器仅侦听来自localhos...
如何利用交换机和端口设置来管理... 在网络管理中,总是有些人让管理员头疼。下面我们就将介绍一下一个网管员利用交换机以及端口设置等来进行D...
施耐德电气数据中心整体解决方案... 近日,全球能效管理专家施耐德电气正式启动大型体验活动“能效中国行——2012卡车巡展”,作为该活动的...
Windows恶意软件20年“... 在Windows的早期年代,病毒游走于系统之间,偶尔删除文件(但被删除的文件几乎都是可恢复的),并弹...
20个非常棒的扁平设计免费资源 Apple设备的平面图标PSD免费平板UI 平板UI套件24平图标Freen平板UI套件PSD径向平...
德国电信门户网站可实时显示全球... 德国电信周三推出一个门户网站,直观地实时提供其安装在全球各地的传感器网络检测到的网络攻击状况。该网站...
着眼MAC地址,解救无法享受D... 在安装了DHCP服务器的局域网环境中,每一台工作站在上网之前,都要先从DHCP服务器那里享受到地址动...
为啥国人偏爱 Mybatis,... 关于 SQL 和 ORM 的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行...