Hi there.
I just need a starting point for a progam I am writing. I need to access a zipped file, and not sure what to do next.
Do I take the file and open it into a special folder, or can I read within a zipped file.
Regards
Hi there.
I just need a starting point for a progam I am writing. I need to access a zipped file, and not sure what to do next.
Do I take the file and open it into a special folder, or can I read within a zipped file.
Regards
How should we know what your app is supposed to do with the zip file? You could - like - unzip the zip file.
You can unzip it with unzip in Shell class.
Or use a plugin from Einhugur’s e-CryptIt Engine for Xojo or my MBS Xojo Compression Plugin with the archive classes to do it within the app.
I don’t know if you are aware of what .cbz or .cbr’s are (comic book files) but I want to be able to open the file to view the .jpg’s inside. That is all cbr’s and cbz’s are.
So I was thinking one way might be to open the file, put it in an application folder and delete it when they close the file.
Regards
Looks like you need to “unzip” multiple files: Comic-Book-Format – Wikipedia .
Not sure what’s the capabilities of the upcoming feature:
But inspecting contents without completely unpacking them would be a great addition
You could look into this:
Unless the tool you use has an unzip to memory, you probably need to unzip to a temp file then read the image.
ZipFolders on Windows used to be great- if a folder was named something.zip, it showed up as a folder in most situations, and unzipped on demand.
(Current Windows doesnt seem to do it quite the same way any more… maybe I broke something…)
Unknown. And you can’t use what may not be available today.
If you need plug-in free, please use unzip via shell class.
How dumb I am, I thought everybody knew what’s upcoming and only I was saying “Not sure what’s the capabilities of the upcoming feature”; also I thought that we could open a hole in the time-space tissue and use it now from the future. Thank you for informing me that I can’t.
The best option by far, without any 3rd party plugins :
My app has similar features, receives and send / expands and compresses ZIP / GZ / TAR and other formats. Use that library above to Inflate / deflate.
Thank you ever so much for this Sveinn. However I have never used GitHub… (sorry never had to).
Can you explain how get get this and use it?
I’m not sure which files I have to get and how to get them sort of thing.
Regards
Read Andrew’s manual, specially this part: How to incorporate zlib into your Realbasic/Xojo project
You can download it here also
Thanks ever so much. I have printed off the docs here so I can read them in peace (I’m old technology and need paper!)
Once again, thank you very much!
Hi Sveinn.
I found another way to do what I want, using shell commands, however I must be doing something wrong, because i never change to the directory I want.
Here is my code:
var s as new shell
var cmd as string
s.Execute ("dir")
window1.TextArea1.text = s.Result
s.Execute ("cd..")
Window1.TextArea1.text = s.Result
s.Execute ("dir")
Window1.TextArea1.text = s.Result
I always stay in the same directory. I never even move up one directory level. Can you see what I am doing wrong?
Regards
Here’s some Xojo code using Windows explorer to unzip a file. Note this is using the older AP1, but should be easy to convert to API2.
Public Sub UnzipWin32(zipfile as FolderItem, ExtractTo as FolderItem)
#if TargetWin32
Dim fso, objShell, FilesInZip, MyFolder1, MyFolder2 As OLEObject
Dim ZipParams(1), ExtractParams(1) As variant
ZipParams(1) = ZipFile.ShellPath
ExtractParams(1) = ExtractTo.ShellPath
// If the extraction location does not exist create it
fso = New OLEObject("Scripting.FileSystemObject")
If NOT fso.FolderExists(ExtractTo.ShellPath) Then
fso.CreateFolder(ExtractTo.ShellPath)
End If
objShell = New OLEObject("Shell.Application")
MyFolder1 = objShell.Invoke("NameSpace", ZipParams)
MyFolder2 = objShell.Invoke("NameSpace", ExtractParams)
//Extract the contants of the zip file.
MyFolder2.CopyHere(MyFolder1.Items)
fso = Nil
objShell = Nil
exception err as OLEException
msgbox err.message
#endif
End Sub
Shell executions are self contained. Once they finish the environment reverts to the original. The exception would be if you’re running in Interactive mode. Then the first command is s.Execute and subsequent commands are issued via Write/Writeline.
CBR are RAR compressed files, unziping will not work, you need an external tool. The easiest way is to use 7z (it is opensource) to uncompress, the advantage is that 7z automatically recognizes the file format and the same code will work for both CBZ and CBR.
To whom it may inspire,
this is my way to renew / update a zipped Database by Downloading in normal User-Account with MAC, WIN or Linux.
This method involves the local installation of updated documents in various formats and a fairly large database, which is transferred in zipped form (supplied by the server as HMV.xml.zip). First, it is checked here whether the user is still using the old version and, if so, the task is terminated.
The file then transferred is successfully unpacked and installed with the on-board resources of the shell (WIN "tar -xvf "…, MAC/LINUX "unzip "…), which has worked without any problems so far.
Warm greetings from Rhineland-Palatinate
Bernd Sebastian
Var url As String = app.sockDom+".homepage.t-online.de/"+app.VerzeichnisOrdner+"/"+DB+"/"+Dok
Var downloadFile As FolderItem
Var cf As Integer
Var timeout As Integer = 60 'sec
#If TargetMacOS
downloadFile = SpecialFolder.ApplicationData.Child("DRG-Recherche Prefs").child(DB).Child(Dok)
#Else
downloadFile = SpecialFolder.Preferences.Child("DRG-Recherche Prefs").child(DB).Child(Dok)
#Endif
Downloader.Purge
Downloader.Yield = true ' synchronously
Anzeige.Value = "File-Transfer gestartet ..."
if Downloader.Get(url, downloadFile, timeout) then ' timeout s.o.
if downloadFile <> Nil and downloadFile.Exists then
loadcount = loadcount+1
newcount = newcount-1
Aktion.Text = Aktion.Text+"Server-Datei """+Dok+""" wurde geladen."+chr(13)
SetBottom
if DB="Individuelle" or DB="Komplexe" or DB="Scores" then DateiChanged = true
else
Anzeige.Value = "File-Transfer abgebrochen"
Aktion.Text = Aktion.Text+"Server-Datei """+Dok+""" ist nicht vorhanden."+chr(13)
SetBottom
end if
if newcount > 1 then DownloadAll.Visible = true else DownloadAll.Visible = false
if loadcount > 1 then ButtonNeu.Visible = true else ButtonNeu.Visible = false
if loadcount > 0 then ButtonOrdner.Visible = true
if DateiChanged then FertigButton.Backdrop = Pfeil_back
If DB = "HMV" then ' HMV entpacken
' Falls HMV App läuft, diese beenden, da bei aktiver Datenbank Neuinstallation nicht möglich
Var m As New Mutex("MutexHV")
If Not m.TryEnter Then
Var sh As New Shell
sh.mode = 0 ' One-shot
#If TargetWindows
sh.Execute("taskkill /IM HMV.EXE /F")
System.DebugLog(sh.Result)
#Else ' MAC / LINUX
sh.Execute("ps -ax | grep HMV")
Var pid As String = sh.Result.ToInteger.ToString
sh.Execute("Kill "+pid)
#EndIf
Aktion.Text = Aktion.Text+"HMV-Tool und Datenbank-Registrierung wurde beendet!"+chr(13)
SetBottom
End If
Aktion.Text = Aktion.Text+"HMV-Datenbank wird entpackt und installiert ..."+chr(13)
SetBottom
Try
Var sh As New Shell
sh.TimeOut = 10000 ' 10s
if downloadFile <> Nil and downloadFile.Exists and not downloadFile.IsFolder then
#If TargetWindows
sh.Execute("tar -xvf "+downloadFile.ShellPath+" -C "+downloadFile.Parent.ShellPath)
if sh.ErrorCode <> 0 then Aktion.Text = Aktion.Text+"err: "+sh.ErrorCode.ToString+" res:"+sh.Result+"path: "+downloadFile.ShellPath+chr(13)
#Else ' Mac & Linux
' hier zuerst die alte DB lokal löschen
downloadFile = downloadFile.Parent.Child("HMV.xml")
if downloadFile <> Nil and downloadFile.Exists then downloadFile.Remove ' ###
sh.Execute("unzip "+downloadFile.ShellPath+" -d "+downloadFile.Parent.ShellPath)
' alternativ mit Folderanzeige (auch in WIN/Linux): downloadFile.Open
#Endif
downloadFile = downloadFile.Parent.Child("HMV.xml")
if downloadFile <> Nil and downloadFile.Exists then ' and not downloadFile.IsFolder then
Aktion.Text = Aktion.Text+"Test: Datenbank entpackt und angelegt."+chr(13)
else
Aktion.Text = Aktion.Text+"Test: Datenbank nicht angelegt!"+chr(13)
end if
Aktion.Text = Aktion.Text+"Installation beendet."+chr(13)
SetBottom
else
Aktion.Text = Aktion.Text+"Entpacken gescheitert!"+chr(13)
Aktion.Text = Aktion.Text+"Bitte neu laden oder Ordner aufrufen und HMV.xml.zip doppelklicken."+chr(13)
SetBottom
end if
Catch
Aktion.Text = Aktion.Text+"Installation fehlgeschlagen!"+chr(13)
SetBottom
End try
end if
Anzeige.Value = "Weitere Datei transferieren oder AbschlieĂźen mit ZurĂĽck-Pfeil"
else
Try
cf = Downloader.ErrorCode
Anzeige.TextColor = &cFF000000
Warnung.Visible = true
Anzeige.Value = "Ăśberlastung! Bitte warten und erneut starten."
Aktion.Text = Aktion.Text+"Server-Datei """+Dok+""" z. Zt. nicht ladbar! Error: "+str(cf)
if cf = -1 then Aktion.Text = Aktion.Text+" timeout "+str(timeout)+" sec"
Aktion.Text = Aktion.Text+chr(13)
Aktion.Text = Aktion.Text+"Evtl. abgebrochene Datei bitte löschen und später neu laden!"+chr(13)
SetBottom
End try
end if
Hi Mar Tin.
It matters not to me (generally) which decompression program I use. I will happily use 7z.
My issue is that if I wish to decompress it, in my manner of doing things, I want to run a command from from my program to decompress to a temporary folder, so I can read the pages in.
What is making me crazy is using the shell command. It seems no matter how hard I try, I can only run one command. Even when I start different shells, I never move through directories to get to where I want to be.
var s as new shell
var s2 as new shell
var s3 as new shell
var cmd as string
s.Execute ("dir")
window1.TextArea1.text = s.Result
s2.Execute ("cd..")
window1.TextArea1.text = "======================"
Window1.TextArea1.text = s.Result
s3.Execute ("dir")
window1.TextArea1.text = "**********************************"
Window1.TextArea1.text = s.Result
Return True
Regards