Monday, July 13, 2015

command line - Windows batch extract zip files, into folders based on zip name and combining similar zips

I have been searching for a way to bulk extract zip files in a directory and extract them into individual folders based on their zip file name.


I found: Extract all Zip's in a directory (incl. subfolders) with a .bat file or dos command


and: https://stackoverflow.com/questions/17077964/windows-batch-script-to-unzip-files-in-a-directory


which do what I wanted. However I realised that I have some zip files that need to be extracted into the same directory. For example:


base dir
|
|
> file.zip
|
> another file.zip
|
> yaf_disk1.zip
|
> yaf_disk2.zip
|
> yaf2_disk1.zip
|
> yaf2_disk2.zip

With the above I would like yaf_disk1 and yaf_disk2 to be extracted into a directory yaf and yaf2_diskX into the directory yaf2.


I have a working script:


for /R "." %%I in ("*.zip") do (
"%ProgramFiles%\7-Zip\7z.exe" x -y -o"%%~dpnI" "%%~fI"
)

which I got from the above links which I mostly (now!) understand. I don't know if it is possible to get a batch file to look at the file, see the diskX at the end and extract all files with same name and diskX into the first directory it created from those files?


I am working with Windows 10 if that is of any importance.

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...