Search code examples
pythonrar

Compare archiwum.rar content and extracted data from .rar in the folder on Windows 7


Does anyone know how to compare amount of files and size of the files in archiwum.rar and its extracted content in the folder?

The reason I want to do this, is that server I'am working on has been restarted couple of times during extraction and I am not sure, if all the files has been extracted correctly.

.rar files are more then 100GB's each and server is not that fast.

Any ideas?

ps. if the solution would be some code instead standalone program, my preference is Python.

Thanks


Solution

  • In Python you can use RarFile module. The usage is similar to build-in module ZipFile.

    import rarfile
    import os.path
    
    extracted_dir_name = "samples/sample"    # Directory with extracted files
    file = rarfile.RarFile("samples/sample.rar", "r")
    
    # list file information
    for info in file.infolist():
         print info.filename, info.date_time, info.file_size
    
         # Compare with extracted file here
         extracted_file = os.path.join(extracted_dir_name, info.filename)
         if info.file_size != os.path.getsize(extracted_file):
             print "Different size!"