rpaframework icon indicating copy to clipboard operation
rpaframework copied to clipboard

RPA.Archive fails to extract in Windows if folder paths have trailing spaces

Open orlof opened this issue 1 year ago • 1 comments

This method is provided as a workaround - it removes trailing spaces (may also fail if same folder names exists with different number of trailing spaces)

import zipfile
import os

def extract_archive_and_remove_trailing_spaces_from_directories(zip_path):
    # Open the zip archive in read/write mode
    with zipfile.ZipFile(zip_path, 'r') as zip_file:
        # Iterate over each item in the archive
        for item in zip_file.infolist():
            # Extract the item's name and remove trailing spaces
            item_name = item.filename.replace(" /", "/")

            # Extract the item and add it to the new archive
            if item.is_dir():
                os.makedirs(item_name)
            else:
                with zip_file.open(item) as source, open(item_name, "wb") as dest:
                    dest.write(source.read())

Should this functionality be integrated into RPA.Archive

orlof avatar May 09 '23 13:05 orlof

we can use 'r' just before zip_path to pass as raw so no problem in spaces. I can do it if you like

ydv-ankit avatar May 22 '23 18:05 ydv-ankit