Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

zipfile.extract throwing CrcError for .7z files

the following code I wrote to extract the files from .7z zip file. Code is throwing "Exception has occurred: CrcError". if I am specifying files one by one code works fine.In for loop it throws CrcError.

    selective_files = 'folder\abc[1].txt,folder\abc[2].txt'
    with py7zr.SevenZipFile(fol_doc_text, 'r') as archive:
        
        allfiles = archive.getnames()
        file_exists_list = []
        for file_name in selective_files.split(","):
            if file_name in allfiles:
                # extract the files in the folders
                archive.extract(awards_extract_location,targets=file_name)
            else:
                print(f'file does not exists in .7z')
                new_file_name = check_and_rename(file_name,allfiles,file_exists_list)
                archive.extract(location,targets=new_file_name)

        extraction works fine for 
        c:\data\extract\folder\abc[1].txt 
        
        throw CRC error with abc[2].txt file.
        c:\data\extract\folder\abc[2].txt 
        
        

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

According to the documentation:

Once extract() called, the SevenZipFIle object become exhausted and EOF
state. If you want to call read(), readall(), extract(),
extractall() again, you should call reset() before it.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading