How to display the uncompressed size of zips? Custom col?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
aliteralmind
Posts: 261
Joined: 02 Dec 2014 16:49

How to display the uncompressed size of zips? Custom col?

Post by aliteralmind »

I have a directory of 71 folders and 71 zip files created from them. I need to confirm that all these folders are indeed properly zipped, by comparing the folder sizes against the *uncompressed* size of (the contents within) each zip file. Currently the "size" column for a zip file is its compressed size. Is there a way to display the uncompressed size, such as with a custom column or some scripting solution?
Windows 8.1, 64-bit

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: How to display the uncompressed size of zips? Custom col

Post by TheQwerty »

Try creating a custom column with this script:

Code: Select all

return eval(regexreplace(regexmatches(zip_list(<cc_item>,,1), '[\d,]+\sbyte','+'), '[^\d+]'));
Explanation:

Code: Select all

// Get the contents listing with sizes for the current item.
$data = zip_list(<cc_item>,,1);

// Extract the raw byte sizes as a summation string.
$data = regexmatches($data, '[\d,]+\s+byte', '+');

// Remove anything that isn't a '+' or digit.
$data = regexreplace($data, '[^\d+]');

// Evaluate the summation string.
$data = eval($data);

// Return the total bytes.
return $data;

EDIT: Forgot to add a snippet:

Code: Select all

Snip: CustomColumn 1
  XYplorer 14.80.0225, 2/3/2015 10:25:08 AM
Action
  ConfigureColumn
Caption
  Uncompressed Size
Type
  3
Definition
  return eval(regexreplace(regexmatches(zip_list(<cc_item>,,1), '[\d,]+\sbyte','+'), '[^\d+]'));
Format
  6
Trigger
  0
Item Type
  0
Item Filter
  zip
Copy then execute the script:

Code: Select all

snippet <clipboard>;
Or right-click the Clear button in the Configure Custom Column dialog and select Paste as Snippet.

admin
Site Admin
Posts: 66300
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: How to display the uncompressed size of zips? Custom col

Post by admin »

Wow, I almost replied the oddly comforting "Nope, not possible." ... :whistle:

aliteralmind
Posts: 261
Joined: 02 Dec 2014 16:49

Re: How to display the uncompressed size of zips? Custom col

Post by aliteralmind »

Beautiful. My first real custom column. Thank you, TheQwerty.
Windows 8.1, 64-bit

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: How to display the uncompressed size of zips? Custom col

Post by TheQwerty »

FYI, some notes (since I was lazy ;))...

1) It's always wise with CCSs to add an early return based on permanent variables so you can easily disable a column without removing it. For instance starting your CCS with something like:

Code: Select all

if ($P_DISABLE_CUSTOM_COLUMNS == true || $P_DISABLE_CC_14 == true) { // (replace 14 with CC's index)
  return 'off';
}
//rest of script.
This way you can disable all Custom Columns (which check these vars) by setting perm $P_DISABLE_CUSTOM_COLUMNS = true; or just a particular column using the $P_DISABLE_CC_## variable instead. (Feel free to give the latter a more descriptive name instead of tying it to the index.)

2) If possible add some early returns to abort the script if not on a specified drive. Rather than let the script churn away on network or portable devices do some light path checking to only run on certain drives.

Code: Select all

if (<curpath> UnLikeI 'C:\*') {
  return 'usd'; //Unsupported drive.
}
Again using permanent variables for the supported drives might be smart.

3) It might be worth checking the zip file's reported size and aborting if it is above some superficial size. You'd probably prefer not knowing the uncompressed size to waiting for it to figure out just how much data is in that 1 GB archive before you can continue browsing.

4) This script is lazy when extracting the sizes. If your archive contains any items whose names look like a size it is going to treat them as sizes even though it shouldn't. A file named '10000000000000 bytes.txt' is going to add an additional 10000000000000 bytes to the total even if the file itself is empty (0 bytes).



Really it all boils down to whittling the total possible execution time of the script down to something that is always acceptable - but you have to leverage that against the increases caused by checking for and avoiding possibly slow conditions.

aliteralmind
Posts: 261
Joined: 02 Dec 2014 16:49

Re: How to display the uncompressed size of zips? Custom col

Post by aliteralmind »

Very grateful for the lesson. I'm bookmarking this post as a reference.
Windows 8.1, 64-bit

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: How to display the uncompressed size of zips? Custom col

Post by bdeshi »

if you have unzip/zipinfo cmdline tool from info-zip.org (UniversalExtractor (which is itself a great util) contains v6.00 of unzip.exe btw), then you can try this custom column which is relatively a bit faster:

Code: Select all

Snip: CustomColumn 1
  XYplorer 14.80.0225, 2/3/2015 11:43:45 PM
Action
  ConfigureColumn
Caption
  ZipSize
Type
  3
Definition
  $fmt="KB";return formatbytes(gettoken(regexmatches(gettoken(runret("""<xypath>\..\cmds\unzip.exe"" -l ""<cc_item>"""),-2,<crlf>),"\d+"),1,"|"),$fmt);
Format
  0
Trigger
  1
Item Type
  0
Item Filter
  zip
replace ""<xypath>\..\cmds\unzip.exe"" with path to unzip.exe
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

Post Reply