VB.NET压缩和解压缩实例全面分析

开发 后端
文章主要介绍了VB.NET 压缩和解压缩的应用实例,如何更好,更快速的对VB.NET 压缩的运用?在这里会为你详细讲解,希望可以给你带来答案。

在我们运用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表间拖放
责任编辑:田树 来源: csdn
相关推荐

2018-09-14 16:18:26

Linux压缩文件应用程序

2012-05-10 09:43:28

2021-02-22 07:58:52

Linux压缩解压

2009-10-28 10:04:53

VB.NET XmlW

2010-01-04 09:27:31

Linux压缩解压缩命令详解

2009-11-02 15:57:36

VB.NET WEB

2009-10-14 15:20:21

VB.NET窗体指针

2009-10-15 10:57:16

VB.NET Text

2009-10-29 15:16:02

VB.NET文件传送

2009-11-04 10:54:53

VB.NET MOVE

2010-01-11 17:58:36

VB.NET压缩ZIP

2023-12-21 07:30:36

PythonZipfileTarfile

2009-10-28 14:34:44

VB.NET Tree

2009-10-21 09:19:40

VB.NET文件压缩 

2010-01-12 10:40:58

VB.NET数据库压缩

2009-10-27 09:45:03

VB.NET数组

2009-11-10 12:27:04

VB.NET远程控制

2010-04-19 16:34:29

Unix操作系统

2010-03-05 09:50:37

Ubuntu ligh

2023-01-30 09:04:56

Linux命令unzip
点赞
收藏

51CTO技术栈公众号