Issue when extracting multiple files within different folders at once

Page 1 of 2 12 LastLast

  1. Posts : 283
    Win 10 Pro x64
       #1

    Issue when extracting multiple files within different folders at once


    So I have a lot of .zips and .rars scattered around one of my hard drives. I wanted to extract all of these to the folders in which they lived in one swift go. So I did a search and selected the .zips to test it out and chose "extract each archive to a separate folder". I used winrar to do this. What happened is archives did NOT all extract to the folder in which they lived. Instead they were ALL extracted to the folder in which the first archive lived. So I was not able to do this extraction of all the archives into their home folder like I liked and ended up having to manually extract one by one while in each archives folder. I also tried to extract with 7zip and had the same result.I'd rather not have to do this with the .rars. Has anyone encountered this issue and know of a fix?
      My Computer


  2. Posts : 75
    21H1 (19043.1415)
       #2

    Huh, you're right. Just tried it with WinRAR's "Extract Here" context menu entry from an Explorer search. It wants to put all the files in the first folder.

    You could do it like this from PowerShell:
    Code:
      Get-ChildItem Z:\YourDir -Include *.zip, *.rar -Recurse | ForEach-Object {& "C:\Program Files\WinRAR\WinRAR.exe" e $_.FullName $_.Directory}
      My Computer


  3. Posts : 283
    Win 10 Pro x64
    Thread Starter
       #3

    Michael said:
    Huh, you're right. Just tried it with WinRAR's "Extract Here" context menu entry from an Explorer search. It wants to put all the files in the first folder.

    You could do it like this from PowerShell:
    Code:
      Get-ChildItem Z:\YourDir -Include *.zip, *.rar -Recurse | ForEach-Object {& "C:\Program Files\WinRAR\WinRAR.exe" e $_.FullName $_.Directory}
    Yeah, very weird. I'll give that a go. Thanks.

    Edit: Sweet that worked. Only thing is that it "extracted here" when I was looking for it to "extract to a separate folder". Would I be able to tweak this to do that? Thanks
      My Computer


  4. Posts : 283
    Win 10 Pro x64
    Thread Starter
       #4

    Michael said:
    You'd just replace that last $_.Directory part with something like Z:\Unzipped, or if you wanted to file them into folders of the same name as the original archives, you could do something like: Z:\Unzipped\$_.BaseName
    Well I don't want to extract them all to a different location. I want them all to extract to a separate folder of the .zip file's name in the current directory the .zip lives.

    So c:\pictures\cats\catpics1.zip should unzip to c:\pictures\cats\catpics1
    and
    c:\pictures\dogs\dogpics1.zip should unzip to c:\pictures\dogs\dogpics1

    Would the below accomplish that?

    Code:
    Get-ChildItem Z:\YourDir -Include *.zip, *.rar -Recurse | ForEach-Object {& "C:\Program Files\WinRAR\WinRAR.exe" e $_.FullName $_.Directory\$_.BaseName}
      My Computer


  5. Posts : 75
    21H1 (19043.1415)
       #5

    Whoops, I realized we should be using WinRAR's X command instead of E to preserve the archive's internal folder structure. And $_.DirectoryName is what we actually want, plus a bit more punctuation to get the string to behave. So yes, you almost had it.

    This will extract archives to folders of the same name, equivalent to "Extract to Folder" from the context menu:
    Code:
    Get-ChildItem Z:\YourDir -Include *.zip, *.rar -Recurse | ForEach-Object {& "C:\Program Files\WinRAR\WinRAR.exe" x $_.FullName ($_.DirectoryName+'\'+$_.BaseName+'\')}
    Last edited by Michael; 12 Mar 2017 at 04:15.
      My Computer


  6. Posts : 283
    Win 10 Pro x64
    Thread Starter
       #6

    Michael said:
    Whoops, I realized we should be using WinRAR's X command instead of E to preserve the archive's internal folder structure. And $_.DirectoryName is what we actually want, plus a bit more punctuation to get the string to behave. So yes, you almost had it.

    This will extract archives to folders of the same name, equivalent to "Extract to Folder" from the context menu:
    Code:
    Get-ChildItem Z:\YourDir -Include *.zip, *.rar -Recurse | ForEach-Object {& "C:\Program Files\WinRAR\WinRAR.exe" x $_.FullName ($_.DirectoryName+'\'+$_.BaseName+'\')}
    Worked like a charm! Thanks for your help.

    Edit: One last thing, I and I'm really not sure if there's a way around this. Is there a way so that it extracts one archive at a time? Right now if I have 20 .zips in a directory it will slowly extract all of them at once, bogging down the machine instead of waiting for the previous one to finish.
    Last edited by bobsagetfullhou; 12 Mar 2017 at 09:31.
      My Computer


  7. Posts : 75
    21H1 (19043.1415)
       #7

    Oh right, hadn't realized because I've been testing with empty files that take a split-second to extract.

    You'll want to add this to the end, before the closing curly bracket:
    Code:
    ; Wait-Process WinRAR
    So like:
    Code:
    Get-ChildItem Z:\YourDir -Include *.zip, *.rar -Recurse | ForEach-Object {& "C:\Program Files\WinRAR\WinRAR.exe" x $_.FullName ($_.DirectoryName+'\'+$_.BaseName+'\'); Wait-Process WinRAR}
      My Computer


  8. Posts : 283
    Win 10 Pro x64
    Thread Starter
       #8

    Michael said:
    Oh right, hadn't realized because I've been testing with empty files that take a split-second to extract.

    You'll want to add this to the end, before the closing curly bracket:
    Code:
    ; Wait-Process WinRAR
    So like:
    Code:
    Get-ChildItem Z:\YourDir -Include *.zip, *.rar -Recurse | ForEach-Object {& "C:\Program Files\WinRAR\WinRAR.exe" x $_.FullName ($_.DirectoryName+'\'+$_.BaseName+'\'); Wait-Process WinRAR}
    Thanks for you help sir! Everything working how I'd like it.
      My Computer


  9. Posts : 283
    Win 10 Pro x64
    Thread Starter
       #9

    Michael said:
    Oh right, hadn't realized because I've been testing with empty files that take a split-second to extract.

    You'll want to add this to the end, before the closing curly bracket:
    Code:
    ; Wait-Process WinRAR
    So like:
    Code:
    Get-ChildItem Z:\YourDir -Include *.zip, *.rar -Recurse | ForEach-Object {& "C:\Program Files\WinRAR\WinRAR.exe" x $_.FullName ($_.DirectoryName+'\'+$_.BaseName+'\'); Wait-Process WinRAR}
    Hey, hate to be a pest, but had one more little issue. If it's extracting a rarset with multiple rars (Cat pics.part1.rar and cat pics.part2.rar) instead of extracting to a folder named Cat pics, it will extract to a folder named Cat pics.part1. Would there be any way to fix this with the script? Im trying to extract a large amount of files and for it to skip extracting dups which have already been extracted. But if it adds the "part1" then it will create it in a whole new folder and not see it as a dup. Thanks
      My Computer


  10. Posts : 75
    21H1 (19043.1415)
       #10

    If your RARs are fewer than 10 parts (numbered part1, part2, ... as opposed to part01, part02; or part001, part002), you can add:
    Code:
    -Exclude *part[2-9].rar
    As in:
    Code:
    Get-ChildItem Z:\YourDir -Include *.zip, *.rar -Exclude *part[2-9].rar -Recurse | ForEach-Object {& "C:\Program Files\WinRAR\WinRAR.exe" x $_.FullName ($_.DirectoryName+'\'+$_.BaseName+'\'); Wait-Process WinRAR}
    If you have any RARs with more than 9 parts, it'll be a bit more complicated.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 19:45.
Find Us




Windows 10 Forums