Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

There was a utility a long time ago called CFAtest that was doing this quite nicely, but it has disappeared.

Basically, I am looking for a similar tool (preferably graphical) that will traverse a given path (preferably including subfolders) and test all zip files that it finds.

Decent logging options would be a plus.

share|improve this question
3  
Which operating system? – Matteo Dec 31 '12 at 10:23

This will find in all subfolders of the current folder (./) the files (-type f) with the extension zip (or ZIP or Zip or zIp and so on, case is ignored, -iname) and test their integrity (unzip -t).

find ./ -type f -iname '*.zip' -exec unzip -t {} \;
share|improve this answer
    
And if you are on Windows and don't have find, install Cygwin. – Daniel R Hicks Jan 23 '13 at 12:23
2  
... or use the for command. – Karan Jul 15 '13 at 6:17
    
... or download gnuwin32.sourceforge.net – Franck Dernoncourt Mar 8 '14 at 18:36
    
If there are many ZIP files, or if they contain many files, less verbose output might be desired. Use unzip's -q option for that: unzip -tq – malamut Mar 19 at 15:56

On Windows I use 7zip: it provides a graphical user interface, is free and supports a wide range of archive file formats including zip.

Navigate to the given folder you want to analyze on Windows Explorer. Search for *.zip, select all files, right-click, select "Test Archive"

enter image description here

Then wait (note that it takes around 10 minutes for explorer.exe to go through 100,000 .zip before 7z start testing):

enter image description here

share|improve this answer

erik's answer didn't work for me on a Mac but this works for zips in current folder and all subfolders:

find . -name '*.zip' -exec unzip -tq {} \;

Outputs this for each file:

No errors detected in compressed data of ./2013-10-16.zip.
share|improve this answer

It might not be quite what you asked for but there is a tool named Zip2Fix.

I haven't used it but you can download it from here:

http://leelusoft.blogspot.com/2011/06/zip2fix-10.html

share|improve this answer

Quick PowerShell command - using 7zip's commandline "t" switch

$7z = "T:\folder\to\7z.exe"
Dir "C:\folder\to\check" -r -include @("*.zip","*.7z") | % { & $7z t $_ -r}

Output

7-Zip 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18

Processing archive: D:\testfile.zip

Testing     my test file.txt
Testing     second file.doc

Everything is Ok

Folders: 0
Files: 2
Size:       10353
Compressed: 5721
share|improve this answer

Here is below a script in Python to test zipfiles located in one or several folders. I tested it on Windows 7 SP1 x64 Ultimate but I would expect it to work on any OS.

Example of output:

Total time spent was 577.64 seconds, checking 100 files, totaling 77.06 GB, 
among which 0 were corrupted.

Script:

'''
Test if the zip files are not corrected
'''

from __future__ import print_function
from __future__ import division

import sys
import zipfile
import glob
import os
import time

def test_zipfile(filepath):
    '''
    Test whether a zipfile is valid
    Some lines were taken from http://stackoverflow.com/questions/4875747/python-script-to-check-if-a-zip-file-is-corrupt
    '''
    start_time = time.time()
    filesize = os.path.getsize(filepath)
    print('Starting testing file: {0} ({1:.2f} MB)'.format(filepath,filesize/10**6), end='')
    the_zip_file = zipfile.ZipFile(filepath)
    ret = the_zip_file.testzip()
    time_spent = time.time() - start_time
    print('\tTest ended. Time spent: {0:.2f} s'.format(time_spent))
    if ret is not None:
        print("First bad file in zip {0}: {1}".format(filepath,ret))
        is_valid = False
    else:
        #print "Zip file is good."
        is_valid = True

    return is_valid, time_spent, filesize


def main():
    '''
    This is the main function
    '''

    # Parameters
    zipfiles_root_folder = '.'
    log_filepath_corrupted = 'result_corrupted.log'
    log_file_corrupted = open(log_filepath_corrupted, 'w')
    log_filepath_valid = 'result_valid.log'
    log_file_valid = open(log_filepath_valid, 'w')
    zipfile_filepaths = sorted(glob.iglob(os.path.join(zipfiles_root_folder, '*', '*.zip'))) # Modify this to whatever folders you need

    # Testing zipfiles
    start_time = time.time()
    total_filesize = 0
    number_of_corrupted_zipfile = 0
    for zipfile_filepath in zipfile_filepaths: # generator, search immediate subdirectories 
        is_valid, test_zipfile_time_spent, filesize = test_zipfile(zipfile_filepath)
        total_filesize += filesize
        if is_valid:
            log_file_valid.write('{0}\n'.format(zipfile_filepath))
        else:
            log_file_corrupted.write('{0}\n'.format(zipfile_filepath))
            number_of_corrupted_zipfile += 1

    # Cleaning  
    log_file_corrupted.close()
    log_file_valid.close()

    time_spent = time.time() - start_time
    print('Total time spent was {0:.2f} seconds, checking {1} files, totaling {2:.2f} GB, among which {3} were corrupted.'.format(time_spent, len(zipfile_filepaths),total_filesize/10**9,number_of_corrupted_zipfile))


if __name__ == "__main__":
    main()
    #cProfile.run('main()') # if you want to do some profiling

It also writes a log file containing all valid zip files as well as a log file containing all corrupted zip files.

Speed benchmark against 7zip: 577.64 seconds Python vs. 609 seconds 7zip

enter image description here

enter image description here

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .