-
Nov 18th, 2012, 10:15 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Unzip in same sub
Alright, I've been using this code to unzip files so that my program can be totally portable-
Code:
Dim Username As String = Environment.UserName
Dim Downloads As String = "C:\Users\" & Username & "\Downloads"
Dim AppData As String = "C:\Users\" & Username & "\AppData\Roaming"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Value Strings
Dim MD As String = Downloads & "\test.zip"
Dim AD As String = AppData & "\testdirectory"
'Unzip test.zip into folder
Dim sc As New Shell32.Shell()
IO.Directory.CreateDirectory(AD)
Dim output As Shell32.Folder = sc.NameSpace(AD)
Dim input As Shell32.Folder = sc.NameSpace(MD)
output.CopyHere(input.Items, 16)
End Sub
But I tried to unzip twice under the same sub like this -
Code:
Dim Username As String = Environment.UserName
Dim Downloads As String = "C:\Users\" & Username & "\Downloads"
Dim AppData As String = "C:\Users\" & Username & "\AppData\Roaming"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Value Strings
Dim MD As String = Downloads & "\test.zip"
Dim AD As String = AppData & "\testdirectory"
'Unzip test.zip into folder
Dim sc As New Shell32.Shell()
IO.Directory.CreateDirectory(AD)
Dim output As Shell32.Folder = sc.NameSpace(AD)
Dim input As Shell32.Folder = sc.NameSpace(MD)
output.CopyHere(input.Items, 16)
'Re-value Strings
MD = AppData & "\HMMI\test.2.zip"
AD = AppData & "\HMMI\test"
'Unzip test2.zip into folder
output.CopyHere(input.Items, 16)
End Sub
Unfortunately that just re-unzips the same file again despite the MD and AD string change. Any ideas on how I can use this method twice?
Last edited by HunterTTP; Nov 18th, 2012 at 10:30 AM.
-
Nov 18th, 2012, 11:37 AM
#2
Re: Unzip in same sub
Surely you need to give the new values of 'MD' and 'AD' to 'output' and 'input' as well? As always with repeated code the best bet would be to make it a separate function/sub and feed the values to it.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Nov 18th, 2012, 01:37 PM
#3
Thread Starter
Addicted Member
Re: Unzip in same sub
Originally Posted by dunfiddlin
Surely you need to give the new values of 'MD' and 'AD' to 'output' and 'input' as well? As always with repeated code the best bet would be to make it a separate function/sub and feed the values to it.
You are the bomb. What would I do without you?
Final working code-
Code:
Dim Username As String = Environment.UserName
Dim Downloads As String = "C:\Users\" & Username & "\Downloads"
Dim AppData As String = "C:\Users\" & Username & "\AppData\Roaming"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Value Strings
Dim MD As String = Downloads & "\test.zip"
Dim AD As String = AppData & "\testdirectory"
'Unzip test.zip into folder
Dim sc As New Shell32.Shell()
IO.Directory.CreateDirectory(AD)
Dim output As Shell32.Folder = sc.NameSpace(AD)
Dim input As Shell32.Folder = sc.NameSpace(MD)
output.CopyHere(input.Items, 16)
'Re-value Strings
MD = AppData & "\HMMI\test.2.zip"
AD = AppData & "\HMMI\test"
output = sc.NameSpace(AD)
input = sc.NameSpace(MD)
'Unzip test2.zip into folder
output.CopyHere(input.Items, 16)
End Sub
Also, I know I can just make this "Sub Zip()" but how would I call it and feed it numbers?
-
Nov 18th, 2012, 04:25 PM
#4
Re: [RESOLVED] Unzip in same sub
vb.net Code:
Private Sub Zip(ByVal MD As String, ByVal AD As String)
Dim sc As New Shell32.Shell() ' I've just copied your code here to show the structure
IO.Directory.CreateDirectory(AD) ' you may need to adapt it for universal use
Dim output As Shell32.Folder = sc.NameSpace(AD)
Dim input As Shell32.Folder = sc.NameSpace(MD)
output.CopyHere(input.Items, 16)
End Sub
Then it's just ...
vb.net Code:
Zip(DownloadPath, NewDirPath) ' I'm guessing on the directories a bit here but you get the idea
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
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
|