Extract Archive breaks when subfolder has space in name


I think in rpaframework==22.0.0 the keyword RPA.Archive.Extract Archive breaks when there is a subfolder with a space in the name. That is, within the file you want to extract, if there is a subfolder with a space in its name, the entire extraction process breaks. Example:

The subfolder is actually created without the space so when it tries to extract files into that subfolder, it (correctly) thinks the subfolder doesn’t exist.

I’m seeing this was implemented for the zipfile library on Windows, which I’m on, so I suppose this is expected.

This was resolved with the following snippet provided by Robocorp staff:

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():
                with zip_file.open(item) as source, open(item_name, "wb") as dest:
1 Like