-2

I use an old program that went out of business, it creates a folder and inside of that "root" folder it creates other folders inside of that folder it creates a rar file of the output from the program that ran.

Root

Folder

   zipfile


Folder

   zipfile

Note that inside of the Root is where there are over 400 folders and each has a zip file inside I need to unrar.

The folder is based on time it was run and this program runs anywhere from 2 times per minute to 6 times a minute so it creates a new folder in the "root" folder based on the time it ran.

To see the information, I need to unrar the file it made in that folder. Problem, I have over 400 folders inside of a central folder, that has to have all the files unrared to the folder they are currently in.

I know WinRar has an unrar here function, and I have generated a text file that has the directory listing of each folder I need to unrar. One folder per line.

Basically I need a batch file that will go to each folder, do a unrar here and move on to the next folder.

Any help available? I am on a Win10 Home system and have my registered version 5.80 of WinRAR. I am not a Powershell user, I am learning it starting today, I did use PowerShell to generate the txt file with the directory listing though.

(Get-ChildItem -Recurse -Filter "zip").FullName | Out-File d:\pattern.txt

So I am not totally clueless.

Thank you.

Responding to Campo, I use WinRar to handle Zips as well as Rars, I do not find I need a zip extractor when I have WinRar installed.

  • First read the documentation of Winrar. There is a command-line usage, which will be very helpful. Then type `for /f` and read the complete output. `for /f` can be used to parse a textile line by line, `for /d` can be used to list all folders. – Stephan Jul 11 '20 at 18:42
  • Could you also please verify whether the file is a `rar file` to `unrar`, or a `zipfile` to unzip! _(I've highlighted the exact terms you've used)_. – Compo Jul 11 '20 at 18:59

1 Answers1

0

The reason I asked about the extension in my comments is because you said that you'd already used powershell to create a filelist using Get-ChildItem, and wanting to start learning it.

As you said you were using PowerShell in Windows 10, I expect that you have, PowerShell v5.0+. This therefore, is a single line for a PowerShell script or to enter directly at the PowerShell Prompt, which should unzip each of your .zip files directly without introducing a third party utility, like WinRAR.

Please change the -Path string according to your specific location.

Get-ChildItem -Path "C:\Users\Frank\Root" -Filter "*.zip" -File -Recurse | ForEach-Object { Expand-Archive -Path $_.FullName -DestinationPath $_.DirectoryName -Force }

You didn't clarify whether you wanted to delete the zip file once you've unarchived it, so if you want that functionality, for the purpose of this exercise you could simply append a deletion command:

Get-ChildItem -Path "C:\Users\Frank\Root" -Filter "*.zip" -File -Recurse | ForEach-Object { Expand-Archive -Path $_.FullName -DestinationPath $_.DirectoryName -Force; Remove-Item $_.FullName }

Please note that the example is only a starting point for you. When you learn more, you can add robustness to it, to prevent for example, deleting a zip file if its extraction failed, and perhaps what to do in the event of errors etc.

Compo
  • 36,585
  • 5
  • 27
  • 39
  • Ok, this gets me further, I now see it trying to work but it fails saying the following... New-Item : An item with the specified name c:\users\frank\complete already exists. – Frank Warmsley Jul 12 '20 at 11:42
  • It sounds to me as if you're trying to overwrite, i.e. something in the archive you're trying to extract, is already in that location. As you did not tell us that some of those files would already be there, I didn't offer that option along with the examples above. You appear to want to use the `-Force` option. I've added it to the answer above. BTW to find out everything about how to use the command, open your PowerShell Prompt, type `Get-Help Expand-Archive -Full`, and press the `[ENTER]` key. – Compo Jul 12 '20 at 11:54