In case you're interested, this is the script I use with 7-Zip for extraction in order to support all archive formats (more than
zip_extract()
anyway). It extracts to the current folder if there is only one item in the root of the archive, or else in a new folder like you desire.
Code: Select all
/* Extracts the selected archives using 7-Zip.
*
* For each archive, if it contains:
* - Only one item in the archive root: the content is extracted directly to the current folder.
* - More than one item in the archive root: the content is extracted to a new folder.
*/
"ExtractWith7Zip"
// Check if there's a file/folder selected
if (Get("CountSelected") == 0) {
Msg("Please select at least one file to extract.", 16);
End(1);
}
$filesPaths = Get('SelectedItemsPathNames', '|');
foreach ($filePath, $filesPaths, "|") {
// Get the list of files/folders present in the root of the zip file
$zipContent = Zip_List2($filePath);
// Compute the number of files/folders present in the root of the zip file
$filesInZipRoot = GetToken($zipContent, "count", "|");
if ($filesInZipRoot > 1) {
// Extract to a new folder
Run("""C:\Program Files\7-Zip\7zG.exe"" x ""$filePath"" -o*");
} else {
// Extract to the current folder
Run("""C:\Program Files\7-Zip\7zG.exe"" x ""$filePath"" -o""<curpath>""");
}
}