Reputation: 5
'Ello,
Using Batch (or Powershell or something), I want to do the following: From folder x, I want to extract all .zip files to their own folder.
Example:
[Folder x]
- a.zip
- b.zip
- c.zip
Into:
[Folder x]
- [a]
- [b]
- [c]
- a.zip
- b.zip
- c.zip
I got until the point that I can extract every zip using the following batch:
for /r %%f in (*.zip) do "C:\Program Files\7-Zip\7z.exe" x "%%f" -o"%%~dpf"
But that resulted in that all contents were extracted to the root folder rather than to a new folder for each zip. I used Script to extract zip files in seperate folders to their own folders as basis for the batch line above.
Any tips?
Upvotes: 0
Views: 2641
Reputation:
NOTE: This is a PowerShell example, which differs significantly from your batch script. Just an FYI.
Assume that you have some ZIP files in the c:\test
folder. The following script will:
c:\test
To make this code work for you, you will need to update:
7za.exe
7za.exe
is contained in the PATH
environment variable, then you do not need to specify the full path to the executable. I simply did it for clarity.Script:
$ZipFileList = Get-ChildItem -Path c:\test\*.zip;
foreach ($ZipFile in $ZipFileList) {
mkdir -Path ('{0}\{1}' -f $ZipFile.Directory, $ZipFile.BaseName);
$ArgumentList = 'x "{0}" -o"{1}\{2}\"' -f $ZipFile.FullName, $ZipFile.Directory, $ZipFile.BaseName;
Start-Process -FilePath c:\windows\7za.exe -ArgumentList $ArgumentList -Wait;
}
Upvotes: 2