Results 1 to 10 of 10

Thread: 7z to extract all files in a folder

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    43

    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

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    43

    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)

  4. #4
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    43

    Re: 7z to extract all files in a folder

    Awesome! Thanks man, I will give this a shot tomorrow morning.

  6. #6

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    43

    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.

  7. #7
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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!

  8. #8

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    43

    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.

  9. #9
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    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:
    1. Dim Arg1 As String = "x" ' this presumably won't change so why use a variable?
    2.             Dim Arg2 As String = "*.mdoc -aoa" ' similarly this
    3.             Dim Zip As String = "c:\users\bsanders\desktop\test\Q113" ' directory might change so use variable
    4.             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?
    5. ' If you can execute using  just 7z in the command window you should be able to do so in Process.Start
    6.             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:
    1. Dim dir As String = """"c:\users\bsanders\desktop\test\Q113"""
    2. ' I've added the extra quotes to save problems if there are 'illegal' characters in the directory name (principally spaces)
    3. ' if you know for certain that there never will be such characters you can do without them
    4.  
    5. 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!

  10. #10

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    43

    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
  •  



Click Here to Expand Forum to Full Width