|
-
Apr 23rd, 2013, 03:30 PM
#1
Thread Starter
Member
7z to extract all files in a folder
working on a part of my program and need to extract all files in a folder to the same folder and finish up the sub by deleting all files with an ext of .mdoc
this is what i'm trying but i'm not having too much luck. anyone else out there have any ideas??
Code:
Public Sub btn_7zip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_7zip.Click
'command line to extract .mdoc files to .pcl files using 7zip
Try
Dim Arg1 As String = "x -0"
Dim Zip As String = "\\cps1\m3\test\Q113 - y"
Dim path As String = G.StagingDirectory
Process.Start("C:\Program Files \7-Zip\7z.exe", Arg1 + path + " " + Zip)
Catch ex As Exception
MessageBox.Show("Error: Extraction Failed")
End Try
End Sub
-
Apr 23rd, 2013, 03:40 PM
#2
Re: 7z to extract all files in a folder
Arg1 + path + " " + Zip = x -0G.StagingDirectory \\cps1\m3\test\Q113 - y
I have no familiarity with 7z but I think it extremely unlikely that that is a valid args line. I presume what you actually want is "x -0" G.StagingDirectory "\\cps1\m3\test\Q113 - y" in which case you're gonna need a whole lot more " and at least one more space.
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!
-
Apr 23rd, 2013, 03:48 PM
#3
Thread Starter
Member
Re: 7z to extract all files in a folder
i appreciate the insight but i'm not fully following what you mean by more " and more space.
process.start("7zlip location", arg1 (as you stated "x -o"), + " " + Zip + " " + path)
-
Apr 23rd, 2013, 07:33 PM
#4
Re: 7z to extract all files in a folder
Well if I have the right argument string it would be ...
Process.Start("C:\Program Files \7-Zip\7z.exe", """x -0"" G.StagingDirectory ""\\cps1\m3\test\Q113 - y""")
... however you want to reach that. Arguments are delimited by space so any space that appears within a single argument requires that the argument be in quotes. To include " in a string it must be 'escaped' as double ".
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!
-
Apr 23rd, 2013, 07:51 PM
#5
Thread Starter
Member
Re: 7z to extract all files in a folder
Awesome! Thanks man, I will give this a shot tomorrow morning.
-
Apr 24th, 2013, 08:48 AM
#6
Thread Starter
Member
Re: 7z to extract all files in a folder
so, i tried the method that you mentioned dunfiddlin. when i debug it just passes right over it not doing anything at all. i did a ton of googling and testing using cmd window and i can get the files to extract if i do it manually in cmd prompt. when i use code i get nothing. here is what i have.
Code:
Public Sub btn_7zip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_7zip.Click
'command line to extract .mdoc files to .pcl files using 7zip
Try
Dim Arg1 As String = "x"
Dim Arg2 As String = "*.mdoc -aoa"
Dim Zip As String = "c:\users\bsanders\desktop\test\Q113"
Dim path As String = "-oc:\users\bsanders\desktop\test\Q113"
Process.Start("c:\program files\7-Zip\7z.exe", """Arg1""Zip""path""Arg2""")
Catch ex As Exception
MessageBox.Show("Error: Extraction Failed")
End Try
End Sub
i tried to write the code exactly as i was able to extract using cmd prompt. in the cmd window i can type
7z e (folder) -o(folder) and it extracts perfectly.
scratching my head over here.
any help is appreciated.
Last edited by bsanders; Apr 24th, 2013 at 08:55 AM.
-
Apr 24th, 2013, 09:05 AM
#7
Re: 7z to extract all files in a folder
7z e (folder) -o(folder) and it extracts perfectly.
So why is what you're putting in the arguments so different? If I knew exactly what you want to use I could be more accurate in what to suggest.
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!
-
Apr 24th, 2013, 09:56 AM
#8
Thread Starter
Member
Re: 7z to extract all files in a folder
that's my bad. the argument 1 should x not e. argument 2 is telling 7z to only extract files ending with .mdoc
what i am trying to accomplish is in my program at this point i will have a network folder with about 4k .mdoc files and 1 .exe, 2 .dll and 1 .bat file. in code i want on button click to fire start up 7z go out to this network folder and extract all of the .mdoc files and overwrite them with .pcl files or just extract the .mdoc files and once that is done delete the .mdoc files leaving me with a networked folder with 4k .pcl files and the other few files i mentioned.
after that i can call the .bat file which converts the pcl files to pdfs and renames them for me to use.
hopefully that makes sense.
-
Apr 24th, 2013, 10:54 AM
#9
Re: 7z to extract all files in a folder
Ok. So the problem is that you're using variables as literals. And being somewhat inconsistent with where you actually need variables at all.
vb.net Code:
Dim Arg1 As String = "x" ' this presumably won't change so why use a variable?
Dim Arg2 As String = "*.mdoc -aoa" ' similarly this
Dim Zip As String = "c:\users\bsanders\desktop\test\Q113" ' directory might change so use variable
Dim path As String = "-oc:\users\bsanders\desktop\test\Q113" ' as I understand it this is only necessary if you want to save to a [I]different[/I] directory?
' If you can execute using just 7z in the command window you should be able to do so in Process.Start
Process.Start("c:\program files\7-Zip\7z.exe", """Arg1""Zip""path""Arg2""") 'not the way to concatenate a string!
So, I'd do it thus ...
vb.net Code:
Dim dir As String = """"c:\users\bsanders\desktop\test\Q113"""
' I've added the extra quotes to save problems if there are 'illegal' characters in the directory name (principally spaces)
' if you know for certain that there never will be such characters you can do without them
Process.Start("7z", "x " & dir & " *.mdoc -aoa"
Obviously I'm still relying on you having the actual commands and switches correct at this point as I've only done a little research on 7z itself.
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!
-
Apr 24th, 2013, 02:43 PM
#10
Thread Starter
Member
Re: 7z to extract all files in a folder
so i got it working awesomely!!! however, you do need a dest to extract to otherwise the default as i have found is inside the 7-zip folder under program files. weird. thanks for your help.
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
|