Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/Compression/unzip with folders
Function:
Required plugins for this example: MBS Compression Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Compression/unzip with folders
This example is the version from Wed, 5th Apr 2016.
Project "unzip with folders.rbp"
FileTypes
Filetype text
End FileTypes
Class Window1 Inherits Window
Control EditField1 Inherits TextArea
ControlInstance EditField1 Inherits TextArea
End Control
EventHandler Sub Open() dim f as FolderItem dim z as UnZipMBS dim lines(-1) as string dim s as string dim info as UnZipFileInfoMBS f=SpecialFolder.Desktop.Child("test.zip") if f=nil or f.Exists=False then MsgBox "You need a test.zip file on your desktop folder." Return end if z=new UnZipMBS(f) dim destfolder as FolderItem = f.Parent.Child("test.zip folder") lines.Append "FileCount: "+str(z.Count) z.GoToFirstFile do dim isFolder as Boolean=false dim path as string = z.FileName // we need to know text encoding, so we guess ASCII here path = DefineEncoding(path, encodings.ASCII) lines.Append "CurrentFileName: "+path if Right(path,1)="/" then isFOlder=true end if if encodings.UTF8.IsValidData(path) then path = DefineEncoding(path, encodings.UTF8) end if f=getpath(destfolder, path) info=z.FileInfo lines.Append "uncompressedSize: "+str(info.uncompressedSize) lines.Append "compressedSize: "+str(info.compressedSize) lines.Append "date: "+info.date.ShortDate+" "+info.date.ShortTime if isfolder then f.CreateAsFolder else dim b as BinaryStream=f.CreateBinaryFile("") if b<>nil then z.OpenCurrentFile if z.Lasterror=0 then do s=z.ReadCurrentFile(100000) b.Write s loop until lenb(s) = 0 z.CloseCurrentFile b.Close end if else lines.Append "Failed to create binary stream for "+f.AbsolutePath end if end if f.ModificationDate=info.Date #if not TargetLinux then f.CreationDate=info.date #endif z.GoToNextFile loop until z.Lasterror<>0 EditField1.text=Join(lines,EndOfLine) End EventHandler
Function getpath(parent as FolderItem, path as string) As FolderItem dim i,c as integer c=CountFields(path,"/") dim f as FolderItem = parent for i=1 to c dim s as string = NthField(path,"/",i) if s<>"" then if f.Exists=False then f.CreateAsFolder end if f=f.Child(s) end if next Return f End Function
Protected Function str(b as boolean) As string if b then Return "true" else Return "false" end if End Function
End Class
MenuBar MenuBar1
MenuItem UntitledMenu1 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS Compression Plugin.




Links
MBS Xojo PDF Plugins