VB.NET壓縮和解壓縮實例全面分析
作者:佚名
文章主要介紹了VB.NET 壓縮和解壓縮的應(yīng)用實例,如何更好,更快速的對VB.NET 壓縮的運用?在這里會為你詳細講解,希望可以給你帶來答案。
在我們運用VB.NET這門語言時,我們嘗嘗會遇到VB.NET壓縮和解壓縮的問題,如何能更好的實現(xiàn)VB.NET壓縮的問題,在這里我們用一個實例給大家詳細分析一下,希望可以給大家?guī)韼椭?/P>
VB.NET壓縮和解壓縮實現(xiàn)代碼:
- PublicEnumZip
- Zip=0'壓縮
- UnZip=1'解壓縮
- EndEnum
- '壓縮、解壓縮
- PublicFunctionZipFile(ByValinDirPathAsString,OptionalByVal_zipAsZip=Zip.Zip,_
- OptionalByValstrFileNameAsString="C:\BACKUP")AsBoolean
- DimInfoAsNewInformation
- DimPrintMessageAsNewErrorinf
- DimstrCommandAsString
- If_zip=Zip.ZipThen
- DimdirectoryEntriesAsString()
- directoryEntries=System.IO.Directory.GetFileSystemEntries(inDirPath)
- DimstrFileAsString,strFileAllAsString
- ForEachstrFileIndirectoryEntries
- strFileAllstrFileAll=strFileAll&"-ep1"&strFile
- Next
- DimstrPassAsString=InputBox(Info.NOR_InputPassword,Info.NOR_PasswordInput)
- IfstrPass.Length>0Then
- strCommand="winrarA-hp"+strPass+"-ep1"
- Else
- strCommand="winrarA-ep1"
- EndIf
- strCommandstrCommand=strCommand&Space(1)&strFileName&Space(1)&strFileAll
- Try
- IfSystem.IO.File.Exists(strFileName)Then
- IfMsgBox(Info.NOR_ReplaceFile,_
- MsgBoxStyle.OKCancel+_
- MsgBoxStyle.Information,Info.NOR_Prompt)=MsgBoxResult.CancelThen
- ReturnFalse
- Else
- Shell(strCommand,AppWinStyle.NormalFocus,True)
- EndIf
- Else
- Shell(strCommand,AppWinStyle.NormalFocus,True)
- EndIf
- MsgBox(Info.SUC_ZipBackSuccess,MsgBoxStyle.OKOnly+MsgBoxStyle.Information,Info.NOR_Prompt)
- ReturnTrue
- Catch
- PrintMessage.WriteErr("Cls_Common->ZipFile",Info.ERR_ZipBackError)
- MsgBox(Info.ERR_ZipBackError,MsgBoxStyle.OKOnly+MsgBoxStyle.Information,Info.NOR_Prompt)
- ReturnFalse
- EndTry
- Else
- DimOpenDialogAsNewOpenFileDialog
- OpenDialog.Filter="還原壓縮數(shù)據(jù)*.rar|*.rar"
- IfOpenDialog.ShowDialog=DialogResult.CancelThen
- OpenDialog.Dispose()
- ReturnFalse
- EndIf
- strFileName=OpenDialog.FileName
- DimstrRePassAsString=InputBox(Info.NOR_InputPassword,Info.NOR_PasswordInput)
- IfstrRePass.Trim.Length>0Then
- strCommand="winrarX-hp"+strRePass.Trim+"-o+-inul-ep2"
- Else
- strCommand="winrarX-o+-inul-ep2"
- EndIf
- strCommandstrCommand=strCommand&Space(1)&strFileName&Space(1)&Application.StartupPath
- OpenDialog.Dispose()
- Try
- Shell(strCommand,AppWinStyle.NormalFocus,True)
- MsgBox(Info.SUC_ZipRevertSuccess,MsgBoxStyle.OKOnly+MsgBoxStyle.Information,Info.NOR_Prompt)
- ReturnTrue
- Catch
- PrintMessage.WriteErr("Cls_Common->ZipFile",Info.ERR_ZipRevertError)
- MsgBox(Info.ERR_ZipRevertError,MsgBoxStyle.OKOnly+MsgBoxStyle.Information,Info.NOR_Prompt)
- ReturnFalse
- EndTry
- EndIf
- 'Debug.Write(strCommand)
- EndFunction
你的應(yīng)用程序的bin下要有一個winrar的可執(zhí)行文件.
【編輯推薦】
責(zé)任編輯:田樹
來源:
csdn