Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Batch unzip with values from a txt file

Posted on 2009-04-01
Medium Priority
Last Modified: 2013-11-10
Hi.  I have a group of 800 zip files that I need to unzip, but I only need to unzip 300 that are in a text or csv file.  They need to be unzipped to a new directory.  Is there any solution that can be run from a command line on the PC or a commercial application out there that will unzip files based on the values of the list?

Question by:johnharbour
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 24041946
you can write a vb or your language of choice prog to use the winzip command line (an add-on) then pass in your parameters

Expert Comment

ID: 24041992
..or, you could unzip them all to one folder, use the list you have with the pkzip command to rezil only the selected files to a new zip file, then unzip that file to your final target directory

Author Comment

ID: 24042449
trying to do it in one step due to time constraints.
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.


Accepted Solution

cmrobertson earned 2000 total points
ID: 24042841
you can use winzip command line right from the command line - it is free to registered users of winzip, I will drop a portion of its documented features in the code window
Using a command window
You can use the add-on in a command window in any of these ways: 
You can type the full name of the WinZip folder followed by the name of the command, which is either "WZZIP" (for zipping) or "WZUNZIP" (for unzipping), followed by the parameters necessary for the operation. For example, if you installed WinZip into the C:\Program Files\WinZip folder and you want to list the contents of, you might type: 
    "c:\program files\winzip\wzzip" -v
(Note that you must use quotes around the command name if the name of the folder includes spaces, as shown above. Otherwise, the quotes are not necessary.) 
You can copy WZZIP.EXE and WZUNZIP.EXE to a folder specified in your PATH environment variable. Then you can run the commands by simply typing "WZZIP" or "WZUNZIP" and the desired parameters, without the name of the WinZip folder: 
    wzzip -v
You can add the WinZip folder to your PATH environment variable, for example: 
    set path=c:\windows;"c:\program files\winzip";...
If you have done this, you can run the commands at the system prompt by simply typing "WZZIP" or "WZUNZIP" followed by the desired parameters, without the name of the WinZip folder:
    wzzip -v
(For information on the PATH environment variable, please refer to your Windows documentation. If you use this method regularly, you will probably want to edit AUTOEXEC.BAT so that the WinZip folder is permanently added to the PATH environment variable.) 
Using the Run dialog
You can use WZZIP.EXE and WZUNZIP.EXE from the Run dialog by simply typing the command name and any desired parameters. It is not necessary to include the WinZip folder, but you may need to specify the folder for the files you wish to work with. For example: 
    wzzip -yp -v c:\temp\
We recommend using the -yp option to keep the MS-DOS command prompt window from closing automatically; otherwise, you will not have much time to look at the results of your command. 
Using batch files
You can use WZZIP.EXE and WZUNZIP.EXE in MS-DOS batch files using the same rules as shown above for command windows. 
The procedure will be similar for script processors other than MS-DOS batch files (application program macros, for example). However, check your documentation for information on how paths should be specified. 
Using return codes (errorlevels)
WZZIP and WZUNZIP will in most cases return a nonzero errorlevel in the event of a serious error; otherwise, an errorlevel of 0 is returned. You can use these return codes in batch files and other automated processing. For example: 
    wzzip *.doc
    If ErrorLevel 1 Goto ErrMsg
    Echo No Known Errors
    Goto Exit

Open in new window

LVL 38

Expert Comment

ID: 24043480
>>> "but I only need to unzip 300 that are in a text or csv file" <<<

Are saying is that you only want to unzip those archives that CONTAIN *.txt or *.csv files
that you have a list of file names for the archives you want to unzip?

Sorry if I didn't understand that, but it seemed ambiguous to me.

Working from a list of *.zip file names would present no great problem if you use the free 7-Zip which is pretty easy to run from the comand line.

Install it and you will find the program folder at "C:\Program Files\7-Zip" if you choose the defaults.  The "windows" executable is "7zFM.exe", but you would be calling the command line program executable "7z.exe".  Print off the "Command Line" usage pages as a reference so you an fine-tune a batch file to suit your requirements if I don't get it quite right. Better still, get a text file with the command line switches:

7z -h > 7-Zip_Usage.txt
7z -? > 7-Zip_Usage.txt

Note that it uses a dash or double dash to preceded command line switches rather than a /  eg. /? for help.

Basic usage for unzipping:

7z.exe e --switch1 --switch2 --oc:\extract_dir

I would say that what you want to do is create a new "output directory" named after each of the *.zip files so you can keep track.

The following command should read through a file list one line at a time and, for each line, use whatever text is on that line for the command to execute.  Processing finishes after the last line of the list file is read.  In this case the *.zip files and the list file are assumed to be in the same directory as the list file:

for /f "tokens=* delims=" %a in (list.txt) do 7z.exe e %a --oc:\extract_dir\%~na

taking that a bit at a time.  The %a variable will hold whatever is on each line of the text file as it is being read, and so should contain the name of the *.zip file to extract.  The %a is also being used to name the output directory by modifying it to exclude the extension.

If used in a batch file, you double up the % symbols for each occurrence of %a.

Try out the attached batch file (after renaming to Unzip.cmd) in a test folder containing about 3 of your *.zip files copied in there along with a list file containing either just the file names of the zip files, or the fully qualified paths to their folder (ie. the current folder).

Let us know what happens and we can fine tune it from there if needed.

LVL 38

Expert Comment

ID: 24043630
If any of your *.zip files contain folders, ie. if unzipped normally with WinZip or the Windows unzipping function the folder hierarchy is recreated, then you should substitute the e for x like this:

start /b /wait %ZipProg% x "%%a" -o"%CD%\%%~na"

This is especially true if the separate folders packed into the zip files contain files with the same filenames.  With the e command, it recreates the folders empty and unpacks all their contents into the root of the new folder created with the name of the zip file, whereas the x command extracts the files to those separate sub-folders of the new folder created.

It would prompt you before overwriting files of the same name in the destination folder, but you would be there all day saying No, and then have to do it all again to ensure the integrity of the contents.

Note that the start /b /wait is there to pause processing between each zip file and stop it from spawning a new command window for each step.

The program is quite picky about what can or must be double-quoted for it to recognise and work with file/folder names or paths with spaces.  I think my command should be OK for your needs.
LVL 38

Expert Comment

ID: 24043680
Just one more thing that is useful to know.  You can copy out 7z.exe and 7z.dll from the program folder to which it installed and use it in another folder if you wanted to uninstall 7-Zip bust still use the command line part of it.

Expert Comment

ID: 24050870
for /f "tokens=*" %A in (ziplist.txt) do 7z.exe e -o.\%A

This will extract all zip files listed in ZIPLIST.TXT to a folder with a name corresponding to the file name.

You can download 7zip from www dot 7zip dot org.
LVL 38

Expert Comment

ID: 24057508
Glad to see another expert agrees with my suggested 7-Zip usage, and the command used does just what the batch file I attached earlier does.
LVL 71

Expert Comment

ID: 24072743
I would have recommended the same - AFAIK 7zip is available as dll to use and control directly from your app.

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Simple Linear Regression

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question