i want to zip and unzip files and folder trough vb but i dont know how to begin, i found that there is a dll called zipfldr but i've found nothing in the forum, if anyone know the syntax i will appreciate your help...
Printable View
i want to zip and unzip files and folder trough vb but i dont know how to begin, i found that there is a dll called zipfldr but i've found nothing in the forum, if anyone know the syntax i will appreciate your help...
vbAccelerator has a freeware ZIP library, example included. Alternativaly, you can require your user to install WinZip and use the app via the command line. :)
i mean without that, only a syntax that automates the process like:
zip ("folder","password") to "destiny folder\file.zip"
unzip ("file.zip","password") to "destiny folder"
im looking for a thing like that
http://www.mvps.org/emorcillo/vb6/shell/xpzip.shtml
only in xp though.
You'd also need the OLELIB.tlb , which is also there. There shouldn't be any dependencies for this as long as the person is using xp.
ok...can you give an example to unzip a file with this?
Hmm.... I guess not :) .
I thought it would include an example, but it didn't. And I couldn't figure it out. Oh well. There isn't really another resource.
me neigther ... i dont understand it and i dont have any idea on how to understand it...
I thought that XP handled .zip files automatically
Not sure how to make them with it though. I use WinZip, so it opens for everything anyways.
Here's what you need to do to use the class from mvps.org..
Extract olelib.tlb and olelib.odl from tl_ole.zip and copy them to your Windows\System32 directory.
Open a command window and navigate to Windows\System32,
eg cd\windows\system32
Register the two files as follows:
Type: regtlib olelib.tlb and press <enter>
Type: regtlib -o olelib.odl and press <enter>
In VB6, start a new project and add a reference to:
Edanmo's OLE interfaces & functions v1.81
Add the CompressedFolder.cls to your project
To create & add files to a zip:To extract files from a zip:VB Code:
Dim z As CompressedFolder Set z = New CompressedFolder z.CreateZip "c:\temp\somefile.zip" ' Create an empty zip file z.CompressFile "c:\temp\filetozip.txt" ' Add a file to the zipHope that helpsVB Code:
Dim z As CompressedFolder Set z = New CompressedFolder z.OpenZip "c:\temp\somefile.zip" ' Open the zip file z.ExtractFile "zippedfile.txt", "c:\temp" ' Extract the file to c:\temp Set z = Nothing
What happens with vbaccelerator's suggestion. You can use Winzip to zip/unzip files using command line.... but you'd need the (registered version of) Winzip installed and the command-line add-in as well. Otherwise... the code won't work.
ok i kinda works...but it give me some errors while extracting files and making the zips..
and before anything....i couln't register the olelib.tlb and olelib.odl because i dont have the regtlib.exe file ...but i added the reference by searching it...can that be the problem?
REGTLIB.EXE should be in your Windows directory. I'm using WinXP Pro SP1a. Adding a reference to olelib.tlb in VB (as you did) will also register the file, so that should be OK. But the ODL file also needs to be registered for the whole thing to work properly. I'd say that's why you're still getting errors.
If you can't find REGTLIB.EXE, I could probably email it to you. I guess it's just a standard OS file.
ok ill appreciate if you send me the file its only the regtlib.exe wich i need or do i need another file to run the regtlib?
I doubt that you really don't have the file...
tanx for the file ... and im sure i didnt have it...but that doesnt matter know....i've registered the 3 files olelib.tlb olelb.odl and olelib2.tlb using start menu, run, regtlib "file" ...
still giving error...
i add the compress folder class module and i wrote this code in a command button, this is the code:
the errors ocurs in this line:VB Code:
Private Sub Command1_Click() Dim z As CompressedFolder Set z = New CompressedFolder z.CreateZip "c:\file.zip" ' Create an empty zip file z.CompressFile "c:\file.txt" ' Add a file to the zip End Sub
i created the txt file so that isn't the problem...VB Code:
' Get the parent folder IDL oDesktop.ParseDisplayName 0, 0, StrPtr(sFolder), lPtr, lPidl, 0
It appears that problems occur when you zip & unzip files in the root directory, ie C:\
Try again but use a different directory, eg c:\temp
I don't know why this happens :confused:
:thumb: that was the problem...now it works....thank you all for your time specially you pnish and buggy programmer you took pretty much time on this....i guess thats all
one last question....how do i extract the files if theres a password in the zip...cause if the txt file inside the zip has a password it just extract the file in blank i mean empty...
Glad to see you've got it working.
Good luck
I'm not sure. Give me a few minutes and I'll see if I can figure it out.Quote:
Originally posted by Undotgiven
one last question....how do i extract the files if theres a password in the zip...cause if the txt file inside the zip has a password it just extract the file in blank i mean empty...
Hmmmm. Got me stumped I'm afraid :confused:
You can query the zip to see if it has a password:
MsgBox z.GetFileInfo("fileinzip.txt", HasAPassword)
and you can set a password on a zip:
z.ShowAddPassword
But I can't see how you can specify a password when trying to extract a password protected file.
Sorry I can't help you. Maybe you could try getting in touch with the author: [email protected]
Good luck
I have actually emailed that person before on something different, but he has never replied, so I wouldn't wait for the reply.
Maybe the password dialog shows if you extract the files. Try to extract a password protected zip file and see what happens.
I'd also try this:
VB Code:
Public Sub RemovePassword() Dim oCtxMenu As IContextMenu Dim tICI As CMINVOKECOMMANDINFO Set oCtxMenu = getContextMenu tICI.cbSize = Len(tICI) tICI.lpVerb = [b]2[/b] 'The add password was '1'. I changed it to '2'. Try it with 3,4 etc. oCtxMenu.InvokeCommand tICI End Sub
ok it work only with 0,1 and 2 i've tested a lot of numbers but it only works with those i even tried negative numbers... but vb crashes :sick: ... and when i use that it doesnt unzip any files its just like entering the correct password and thats all it doesnt do anything else...
somebody there? plz help!....
I found this on the vbAccelerator web site. I don't know if this is the same prog that TheVader & Mc Brain were talking about, but it appears to work OK (and I don't have WinZip on my PC).
Give it a go and see what you reckon :thumb:
Without looking too closely, that file I posted appears to only ZIP files, not UNZIP.
Checkout this site, it looks promising: http://www.info-zip.org/
This is where the info-zip site eventually leads:
http://www.gzip.org/zlib/
Looks like you guys have zipping and unzipping down. But what if I just want to read the contents of the zip file and display the file names or store the file names in a database?
I believe the software from mvps.org can do this.
Here's the link again....
http://www.mvps.org/emorcillo/vb6/shell/xpzip.shtml
You can try this new project which has no external DLL dependancies -- https://github.com/wqweto/ZipArchive
This is a single-class pure VB6 library for zip archives management with ASM speed (uses bytecode thunks) that supports the original ZipCrypto and the stronger AES encryption for password protected archives.
cheers,
</wqw>
VERY interesting.
I tried the vbZip project, and it works flawless.
Like this:
When I want to use your work in my projects, I only need to unzip a zip file to a folder.Code:vbzip -o "T:\ZIPTEST" x "T:\Desktop\bla.zip"
I tried the basic project.
This doesn't create the folder to extract to.Code:Private Sub Command4_Click()
Dim dblTimer As Double
Dim bResult As Boolean
Dim sLastError As String
dblTimer = Timer
Set m_oZip = New cZipArchive
m_bCancel = False
With m_oZip
.OpenArchive "T:\Desktop\bla.zip"
Set m_oExtractInMemory = m_oZip
bResult = .Extract("T:\ZIPTEST")
Set m_oExtractInMemory = Nothing
sLastError = .LastError
End With
Set m_oZip = Nothing
labProgress.Caption = IIf(bResult, "Done. ", sLastError & ". ") & Format(Timer - dblTimer, "0.000") & " elapsed"
End Sub
And even when the folder exists, no extracted file comes in.
I thought the .Extract method would do this.
Can you give me a hint please?
Karl
@Karl77: I'm sorry for the confusing sample you found but you don't need the lines that set m_oExtractInMemory to make it work. This particular sample shows how to intercept BeforeExtract event and (selectively) re-route target file of extraction to a memory stream, that's why there is nothing extracted on disk.
You can check out the samples in README in the repos home-page/root for a quick intro to class usage, for instance this simple one extracts all zipped files to a folder on disk:
cheers,thinBasic Code:
With New cZipArchive .OpenArchive "test.zip" .Extract "extract_folder" End With
</wqw>
Thank you! This is really an impressing piece of code!
However, it uses techniques which obviously make some AV vendors' alarm bells ring ... see this VirusTotal result with a test program I made.
So for now I had to switch back to Edanmo's CompressedFolder.cls. Nevertheless I'm busy now sending emails to those AV vendors asking for investigation of the issue. Let's see what happens ...
Wolfgang
Too bad as I don't have any false positives when the class is part of a larger project.
I'll probably need to obfuscate it further to fool the AV vendors for 100% fool-proof solution. Something like bare LoadLibrary+GetProcAddress approach :-))
cheers,
</wqw>
@Wolfgang Enzinger: Btw, just tested vbzip.exe (the command-line zip utility from projects test directory) and only machine-learning engines raise alerts on VirusTotal. Removing the call to VirtualAlloc reduced these to only one ML engine so (most probably) using the class is pretty safe in the wild.
Now, why your project raises so much false alarms is another topic but my point is that you might have troubles w/ AVs whichever zip impl is used, might be getting false alarms for totally unrelated to zip archives management reasons.
cheers,
</wqw>
That, or a combination of some things. My project is a console application using Karl E. Peterson's MConsole. That alone usually doesn't trigger any false alarms, but maybe in combination with other techniques it does, who knows.
Anyway, Avira meanwhile confirmed that this is a false positive.
Wolfgang
Since you're using the RC5, perhaps the "zipfile" virtual table binding would be another alternative for you...?
SQL = "Select * From zipfile('" & FileNameOnDisk & "')"
At work, we use (and "ship") it already (since a year or so), to deal with Office-Documents (*.xlsx, *.docx)
(for "user-template-based reporting").
Olaf
Cool! Until now I was unaware that The SQLite Zipfile Module is already compiled into RC5.
Well, for this specific program I'll stay with Edanmo's CompressedFolder.cls because ... this is kind of an "admin tool", and those admins love to copy the EXEcutable file only to any folder and then complain that it doesn't work ... so this tool should have zero dependencies. But for other projects this will come in handy.
Wolfgang
wqweto will your class run in a separate thread ?
I am currently using shell to zip and unzip
WP
You can read encryption support section in repository's README for some guidance.
cheers,
</wqw>
Sorry for being late but you can look at this link...
https://vbmania.com.br/index.php?modulo=detalhe&id=7076
The program is in Portuguese .... it is very simple, but you can use the google translator to translate it to your languag
If you have comments it will be in Portuguese of Portugual ..... as I said google translator can be used ..... I always do that ...
Thanks, Episcopal. However, this works only if WinZip is installed. Perhaps you could add other checks, such as for this key:
HKEY_CLASSES_ROOT\Applications\7zFM.exe\shell\open\command
Users have all kinds of archivers installed. WinZip is not free, therefore it's less likely to find it. Or maybe you find an installation, but the trial period is over...
Check the HKEY_CLASSES_ROOT\.zip key, and get thoroughly lost in the registry. For example, I have dozens of entries for "C:\Program Files (x86)\PeaZip\PEAZIP.EXE" "-ext2here" "%1" although I always use 7-Zip or FreeArc. Every mad software developer thinks he has the right to pollute the registry.
HKEY_CLASSES_ROOT\Applications is a good starting point for a search for installed archivers.
HKEY_CLASSES_ROOT\zip_auto_file\shell\open\command might yield a result, too.
It's one big fat mess - therefore I appreciate wqweto's effort to find a solution that doesn't depend on third party installations.