import py7zr
import zipfile
import os
def extract_7z(archive_path, extract_path):
with py7zr.SevenZipFile(archive_path, mode='r') as archive:
archive.extractall(path=extract_path)
def create_zip(source_folder, output_path):
with zipfile.ZipFile(output_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
for root, dirs, files in os.walk(source_folder):
for file in files:
file_path = os.path.join(root, file)
zipf.write(file_path, os.path.relpath(file_path, source_folder))
def convert_7z_to_zip(archive_path, zip_path):
# Create a temporary directory to extract the 7z file
temp_extract_path = 'temp_extract'
os.makedirs(temp_extract_path, exist_ok=True)
# Extract the 7z file
extract_7z(archive_path, temp_extract_path)
# Create the zip file from the extracted content
create_zip(temp_extract_path, zip_path)
# Clean up the temporary directory
for root, dirs, files in os.walk(temp_extract_path, topdown=False):
for file in files:
os.remove(os.path.join(root, file))
for dir in dirs:
os.rmdir(os.path.join(root, dir))
os.rmdir(temp_extract_path)
def batch_convert_7z_to_zip(directory_path):
for file_name in os.listdir(directory_path):
if file_name.endswith('.7z'):
archive_path = os.path.join(directory_path, file_name)
zip_path = os.path.join(directory_path, file_name.replace('.7z', '.zip'))
print(f'Converting {archive_path} to {zip_path}')
convert_7z_to_zip(archive_path, zip_path)
print(f'Finished converting {archive_path}')
# Usage example
directory_path = 'path_to_directory_with_7z_files'
batch_convert_7z_to_zip(directory_path)
To embed this program on your website, copy the following code and paste it into your website's HTML: