To achieve your goal of compressing numerous folders into archives with a size limit of 10 MB per archive, while maintaining the folder structure and leveraging parallel processing, you can use the 7z compression format provided by 7-Zip. The 7z format supports multi-threaded compression and allows you to split archives into volumes of a specified size.
Here's why 7z is suitable for your needs:
-
Multi-threaded Compression: The 7z format and the 7-Zip utility support multi-threading, which means you can compress multiple files and folders in parallel, effectively utilizing your CPU cores to speed up the compression process.
-
Volume Splitting: 7-Zip allows you to set a maximum size for archive volumes. When you specify a size limit (e.g., 10 MB), it will split the compressed data into multiple archives that do not exceed this size, which is exactly what you require.
-
Maintaining Folder Structure: When you compress directories with 7-Zip, it preserves the folder hierarchy within the archive. Each archive will include the corresponding files and folders, so your original structure remains intact upon extraction.
-
High Compression Ratios: The 7z format often provides better compression ratios compared to formats like ZIP, which can help in reducing the overall size of your archives.
Implementation Steps:
-
Install 7-Zip: If you haven't already, download and install 7-Zip from https://www.7-zip.org/.
-
Use Command-Line for Automation: You can use the 7z command-line utility to automate the compression process over multiple folders. Here's a sample script that you can adapt:
@echo off
setlocal enabledelayedexpansion
set THREADS=4
set MAX_SIZE=10m
set INPUT_DIR=C:\Users\lucas\Downloads
set OUTPUT_DIR=C:\Users\lucas\Compressed
mkdir "%OUTPUT_DIR%"
for /d %%D in ("%INPUT_DIR%\<folder_pattern>*") do (
start "" /b /wait 7z a -t7z -mmt=%THREADS% -v%MAX_SIZE% "%OUTPUT_DIR%\%%~nD.7z" "%%D"
)
Replace <folder_pattern>* with the pattern that matches your folders (e.g., a* for folders starting with 'a'). Adjust THREADS to the number of CPU cores you want to use.
-
Adjust Parameters as Needed:
-t7z specifies the 7z archive format.
-mmt=%THREADS% sets the number of threads for multi-threading.
-v%MAX_SIZE% sets the volume size limit to 10 MB.
"%OUTPUT_DIR%\%%~nD.7z" specifies the output archive name based on the folder name.
Explanation of the Process:
- The script loops through each subfolder in your
Downloads directory that matches the specified pattern.
- For each folder, it starts a background process to compress the folder into volumes not exceeding 10 MB.
- The
start command with /b and /wait ensures that processes run in parallel but wait for all to finish before moving on.
- Multi-threading is leveraged within each compression process, and multiple compression processes run in parallel.
Note on Parallel Processing:
While 7-Zip supports multi-threaded compression, running multiple instances in parallel can further speed up the process if you have many folders. However, be cautious with the number of parallel processes to avoid overloading your system.
Summary:
- Algorithm/Extension: 7z compression format using 7-Zip.
- Features Utilized:
- Multi-threaded compression for parallel processing.
- Volume splitting to enforce the 10 MB size limit.
- Preservation of folder structures within archives.
By using the 7z format and 7-Zip's capabilities, you can efficiently compress your folders into size-limited archives while maintaining the desired folder structures and leveraging parallel processing.
References:
Answer: Use the 7z compression format (from 7-Zip), which supports multi-threading and creating size-limited archives while keeping folder structures intact.