View Full Version : ZIP files

29-06-2011, 12:52
Hey, there again :)

I am wondering if its possible to ZIP files (Create an archive file which is smaller in size and compressed) I assume it would be a function that would require saving in binary...

I have looked at ZLIB but that's only used to ZIP:confused: string information and not files such as bmp, or JPG.

Is there a method to do this? From within Thin Basic?

Thanks you!

29-06-2011, 14:36
Hi Henry.

Actually thinBasic allows compressing/decompressing of strings buffer using STRZIP$ (http://www.thinbasic.com/public/products/thinBasic/help/html/strzip$.htm) and STRUNZIP$ (http://www.thinbasic.com/public/products/thinBasic/help/html/strunzip$.htm) functions.
No native compress/decompress file functions are available.
To compress the content of a file on disk can be done with something like:

sCompressedBuffer = STRZIP$(File_Load(<your full path file name>))
but this will just create a compressed string buffer of your disk file content.

Adding new native functionalities letting basic compress/decompress handling of files is not that complex.
Can you be so kind to describe more what you need to do so I can better understand the direction to go?


29-06-2011, 15:59
Thanks Eros.

I want to ZIP the file in the same directory. It will be used to as script that will compare files in the directory based on their date modifided if they are older then X days they will be ziped. ( I have started this i can do this not a problem)

I have made the following code i dont know if its right so far. But it reads the file i just need to write the part to save it.
Currently i have:

Uses "FILE"
Uses "ZLIB"

Dim FileName As String = APP_ScriptPath + "myfile.txt" ' Set the file name to use'
Dim sCompressedBuffer As String
Dim sCompressedBuffersave As String
Dim FileHandle As DWord

sCompressedBuffer = StrZip$(FILE_Load(FileName))
sCompressedBuffersave = StrZip$(FILE_Save(,"myfile2.txt"))

I was looking at the example of FILE_SAVE but i can't manage to get it to save. Do i need to load the file then open it up then save it? Or would it require FILE_GET, FILE_SEEK,_FILE CLOSE?

Thank you for your time.

29-06-2011, 17:13
The following line is not correct and mainly has no meaning:

sCompressedBuffersave = StrZip$(FILE_Save(,"myfile2.txt"))

FILE_Save save a string buffer to a file binary or not. It just create a file and put into that file a string buffer up to 2GB of data.

Consider that compressing a string buffer is not the same as compressing a file into a zip archive even if you load the string buffer from the file.
I need to develop specific functions that are able to create zip archives, add or extract files to zip archives, ... and so on.

Now I have more info. I will work on that but nothing for the day after, sorry, I need some time to think what is is the best way to do it.

In the meantime if you are in hurry you can follow tip indicated by Michael here: http://www.thinbasic.com/community/showthread.php?10938-Is-it-possible-to-make-a-archive-extracting-script-in-thinbasic


29-06-2011, 23:46
Thanks yes, i understand ill have a go with 7ZIP i was thinking of do that. But wans't sure if i could of have used shell command. Thanks for the link ill keep you posted!