Skip to content

Archive.extractall hangs on password protected .rar file without throwing exception #13

@lennier1

Description

@lennier1

I'm writing a python script to process some old archives that include many .rar files. I can successfully extract data from them using Archive.extractall from pyunpack. However, occasionally I will hit a password protected file, and the program just hangs. I have the code in a try block, but it's not throwing any exception. Would it be possible to throw an exception in this circumstance so my script can skip the file and continue?

Here's the relevant portion of my code:

import os
import rarfile
from pyunpack import Archive

for subdir,dirs,files in os.walk(directoryToExtract):
        for file in files:
            if rarfile.is_rarfile(os.path.join(subdir, file)):
                print("Found rarfile " + os.path.join(subdir, file))
                try:                    
                    Archive(os.path.join(subdir, file)).extractall(os.path.join(subdir, file[0:len(file)-4]),auto_create_dir=True)
                except Exception as e:
                    print("ERROR: Couldn't unrar " + os.path.join(subdir, file))
                    print(str(e))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions