|
-
Jul 5th, 2010, 12:22 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Extract a .zip file
How can i extract all the files from a .zip file into a directory? I have to do this because no free file hosting allows .exe files so im going to have my program download the .zip file containing the .exe then extract that file when its downloaded.
-
Jul 5th, 2010, 12:27 PM
#2
Re: Extract a .zip file
You can do it directly with VB.NET, but I generally prefer not to. I think you have to look up ZipSharLib, or something like that. It's an external dependency that allows you to incorporate zipping.
I always prefer to use 7za, which is a command line zip utility that you can package with you app and then just send the appropriate arguments to zip or unzip files I've used it extensively with one of my apps.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jul 5th, 2010, 12:44 PM
#3
Thread Starter
Fanatic Member
Re: Extract a .zip file
Would it mean having to have something else in the app directory? How would i do it directly?
-
Jul 5th, 2010, 01:10 PM
#4
Re: Extract a .zip file
 Originally Posted by Emcrank
Would it mean having to have something else in the app directory? How would i do it directly?
Yes. You'd have to include the app with your application.
That's generally preferred. I wouldn't know how to use the library I mentioned, since I've never used it.
Though the first place to start would be the documentation and Google. I still find your quote to be ironic, given the amount of research put into the questions... well, rather the lack thereof
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jul 5th, 2010, 01:18 PM
#5
Thread Starter
Fanatic Member
Re: Extract a .zip file
I have searched google and visited many sites but they all include downloading something and putting it in your app's folder. I really want to avoid this. Ill try the documentation now.
-
Jul 5th, 2010, 01:52 PM
#6
Re: Extract a .zip file
 Originally Posted by Emcrank
I have searched google and visited many sites but they all include downloading something and putting it in your app's folder. I really want to avoid this. Ill try the documentation now.
Even with the SharpZipLib, you'll have to include its dependencies, which are most likely .DLLs. And in those cases, when the app is installed, they will be saved on the user's PC.
At the very least, you can include the 7za as a resource and write it to a temp location, unzip the files, then delete it.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jul 5th, 2010, 02:16 PM
#7
Thread Starter
Fanatic Member
Re: Extract a .zip file
could you show me an example how to unzip and zip 7za? Thankyou
-
Jul 5th, 2010, 02:24 PM
#8
Re: Extract a .zip file
 Originally Posted by Emcrank
could you show me an example how to unzip and zip 7za? Thankyou
You should really remove the quote from your signature. It's philosophy that is great in nature, but only valid when executed. It does not represent your actions thus far.
It took me some time and a lot of testing to figure out how to use 7za properly with VB. I wouldn't want to deprive you of that learning experiencing.
When I wanted to learn how to use 7za, I did this and found this.
Once you figure out how to use it, it's relatively simple with Process.Start. Just define a variable as a new process, assign the StartInfo.Arguments, StartInfo.WorkingDirectory, .StartInfo.FileName and the call start on your previously defined variable.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jul 5th, 2010, 02:31 PM
#9
Thread Starter
Fanatic Member
Re: Extract a .zip file
Oh is the 7za way like some Shell ways i found on google?? I want to try and keep it in Vb as much as i can like just have a class and subs in that class then call the subs and pass arguments to the subs. Do you understand me? Any other unzipper thing you can suggest what would allow me to do this?
-
Jul 5th, 2010, 03:48 PM
#10
Re: Extract a .zip file
7za is a command line utility. It's your best option.
The only other way I know of is to include a zip library made for VB. The only library I'm awre of is ZipSharLib. However, like I mentioned before, I've never used it.
Why don't you want to include 7za? I've seen a lot of applications, personal and commercial, that use a 3rd party app like 7za for purposes such as these. There's no shame in it =/
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jul 5th, 2010, 04:01 PM
#11
Thread Starter
Fanatic Member
Re: Extract a .zip file
Its just i hate it when i have exra things in the directory than the executable, is there any documentation on MSDN about the built in way?
Ill try the documentation now.
I couldn't find anything i dont know how to navigate that site properly could you post a link or something to it. It would be much appreciated, also where can i download this ZipSharLib?? I will try that if i cannot figure out the built in way. Thankyou in advance.
-
Jul 5th, 2010, 05:25 PM
#12
Re: Extract a .zip file
is there any documentation on MSDN about the built in way?
There is no built in way. I never said there was. I only mentioned there was a way of doing it with VB.NET via SharpZipLib. But that's a 3rd party library that can be included in .NET applications. You can find more information at their website, located here. Please Google the things I'm telling you. If you had Googled ZipSharpLib, you would have obtained at least some general information about it.
You're not helping me help you. If you're not willing to do the research, then just stop. We're all willing to help, but we will lose interest if you're not showing us that you're trying.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jul 5th, 2010, 05:48 PM
#13
Thread Starter
Fanatic Member
Re: Extract a .zip file
Sorry i have been trying i just havn't shown it i did find some DLL's which were meant to let you manage .zip files earlier but they didn't work. Also when i try download ZipSharp it says page cannot be found, Do you have a copy? or know anywhere else to get one? Look this is the website to download it from(i think) and the 2 links at side dont work. http://www.carto.ca/
-
Jul 5th, 2010, 05:51 PM
#14
Thread Starter
Fanatic Member
Re: Extract a .zip file
Ok i found a website to download it from: http://www.brothersoft.com/sharpzipl...oad-27636.html Can you check that this is the correct one your talking about.
-
Jul 5th, 2010, 05:55 PM
#15
Re: Extract a .zip file
 Originally Posted by Emcrank
That looks fine, but you can download it directly, from here.
CodeBank contributions: Process Manager, Temp File Cleaner
 Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Jul 6th, 2010, 03:49 AM
#16
Re: Extract a .zip file
Why not use the built-in unzipping utility of windows? You can reference Shell32.dll then try the following codes. They are in C# but it can be easily converted.
Code:
private void ExtractZip(string zipFile, string destination)
{
Shell32.Shell shell = new Shell32.Shell();
shell.NameSpace(destination).CopyHere(shell.NameSpace(zipFile).Items(), null);
shell = null;
MessageBox.Show("Done");
}
private void button1_Click(object sender, EventArgs e)
{
ExtractZip(@"C:\PIS\ENUMWINDOWS.zip", @"C:\PIS\Test\");
}
-
Jul 6th, 2010, 10:05 AM
#17
Thread Starter
Fanatic Member
Re: Extract a .zip file
Where can i find the Shell32.dll to reference to - What folder is it in?
Also how can i create a zip file?
Last edited by Emcrank; Jul 6th, 2010 at 02:48 PM.
-
Jul 6th, 2010, 02:44 PM
#18
Thread Starter
Fanatic Member
Re: Extract a .zip file
VB.NET Code:
Private Sub ExtractZip(zipFile As String, destination As String) Dim shell As New Shell32.Shell() shell.[NameSpace](destination).CopyHere(shell.[NameSpace](zipFile).Items(), Nothing) shell = Nothing MessageBox.Show("Done") End Sub Private Sub button1_Click(sender As Object, e As EventArgs) ExtractZip("C:\PIS\ENUMWINDOWS.zip", "C:\PIS\Test\") End Sub
ok i tried to convert it, is that correct??
-
Jul 7th, 2010, 12:52 AM
#19
Re: Extract a .zip file
Shell32.dll is usually located in C:\Windows\System32\. Did you try running it if it is successful? Here's another translation in case yours does not work.
Code:
Private Sub ExtractZip(ByVal zipFile As String, ByVal destination As String)
Dim shell As Shell32.Shell = New Shell32.Shell
shell.NameSpace(destination).CopyHere(shell.NameSpace(zipFile).Items, Nothing)
shell = Nothing
MessageBox.Show("Done")
End Sub
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
ExtractZip("C:\PIS\ENUMWINDOWS.zip", "C:\PIS\Test\")
End Sub
-
Jul 7th, 2010, 11:27 AM
#20
Thread Starter
Fanatic Member
Re: Extract a .zip file
Thankyou that worked perfectly, mine didn't :/. How do i create a .zip file with files in?
Last edited by Emcrank; Jul 7th, 2010 at 12:06 PM.
-
Jul 8th, 2010, 01:04 AM
#21
Re: Extract a .zip file
This is my VB6.0 code to create a zip file, you can convert it to VB.Net, they look similar. And this uses late-binding, you can just use early-binding.
Code:
Public Sub ZipFile(ByVal strFileToZip, ByVal strTargetZip)
CreateEmptyZip strTargetZip
CreateObject("Shell.Application").Namespace(strTargetZip).CopyHere strFileToZip
End Sub
Private Sub CreateEmptyZip(ByVal sPath As String)
Dim strZIPHeader As String
strZIPHeader = Chr$(80) & Chr$(75) & Chr$(5) & Chr$(6) & String$(18, 0) ' header required to convince Windows shell that this is really a zip file
CreateObject("Scripting.FileSystemObject").CreateTextFile(sPath).Write strZIPHeader
End Sub
-
Jul 8th, 2010, 03:17 AM
#22
Re: Extract a .zip file
I have done shell invoking as shown here, but found that it seems to run incredibly slowly, even for small files.
-
Jul 8th, 2010, 11:19 AM
#23
Thread Starter
Fanatic Member
Re: Extract a .zip file
How do i use early bindings?
-
Jul 8th, 2010, 11:48 AM
#24
Frenzied Member
Re: Extract a .zip file
Try this ... it works great.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|