Items count for archives zip rar 7z

Features wanted...
Post Reply
vasya
Posts: 57
Joined: 16 Sep 2019 09:18

Items count for archives zip rar 7z

Post by vasya »

Maybe to show items count in the archives? (optional column)

Image

Code for VB:

Code: Select all

z = UBound(Split(CreateObject("WScript.Shell").exec("""Rar.exe"" lb ""rar""").StdOut.ReadAll, Chr(13)))
z = UBound(Split(CreateObject("WScript.Shell").exec("""7z.exe"" l -ba -slt ""zip""").StdOut.ReadAll, "Path ="))
z = UBound(Split(CreateObject("WScript.Shell").exec("""7z.exe"" l ""zip""").StdOut.ReadAll, Chr(13)))
z = UBound(Split(CreateObject("WScript.Shell").exec("""7z.exe"" l -ba -slt ""7z""").StdOut.ReadAll, "Path ="))
z = UBound(Split(CreateObject("WScript.Shell").exec("""7z.exe"" l ""7z""").StdOut.ReadAll, Chr(13)))
z = CreateObject("Shell.Application").Namespace("zip").Items.Count
else one for example:

Code: Select all

cmd = """" & Soft & """" & " l -ba -slt " & """" & FilePath & """" 
Elements = CreateObject("WScript.Shell").exec(cmd).StdOut.ReadAll
z = Ubound(Split(Elements , "Path ="))

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Items count for archives zip rar 7z

Post by highend »

Why don't you use a scripted custom column?
One of my scripts helped you out? Please donate via Paypal

vasya
Posts: 57
Joined: 16 Sep 2019 09:18

Re: Items count for archives zip rar 7z

Post by vasya »

highend wrote: 06 Feb 2020 17:10 Why don't you use a scripted custom column?
Configuration - Information - Custom Columns - (Undefined) - Edit - Type: Script
Which script I have to use for it?

fishgod
Posts: 222
Joined: 03 Feb 2008 00:40
Location: Sankt Augustin (near Bonn), Germany

Re: Items count for archives zip rar 7z

Post by fishgod »

Right Click Column Header -> Add Column -> Right Click that Column -> Select Custom Column -> select an unused Column -> now again Rightclick the Columnheader -> Edit Custom Column ...# -> fill like this:

Code: Select all

"Archive Count"
  $list = runret("C:\PG\7-Zip\7z.exe l -slt ".quote(<cc_item>));
  $len = strlen($list);
  $newlen = strlen(replace($list, "Path = "));
  return ($len-$newlen)/strlen("Path = ");
Attachments
archive-count.png
archive-count.png (9.79 KiB) Viewed 2459 times
Operating System: Win10 x64 / Win7 x64 / almost allways newest XY-beta
totally XYscripting-addicted

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Items count for archives zip rar 7z

Post by highend »

Something like:

Code: Select all

$tool = "D:\Tools\7-Zip\7za.exe";
    $result = gettoken(trim(runret("""$tool"" l ""<cc_item>"""), <crlf>), -1, <crlf>);
    return regexmatches($result, "\d+? files?") . " " . regexmatches($result, "\d+? folders?");
One of my scripts helped you out? Please donate via Paypal

vasya
Posts: 57
Joined: 16 Sep 2019 09:18

Re: Items count for archives zip rar 7z

Post by vasya »

Image

Mmm, personal language
XYplorer.chm - Advanced Topics - Scripting + Scripting Commands Reference - need to read

In the First script need to add something like this:

Code: Select all

  $Count = ($len-$newlen)/strlen("Path = ");
  If $Count > 0 {$Count = $Count - 1};
  return $Count;
In the rar need to split by "CRC32" (like Path=) and count it: (for first script) (or use lb and just count strings)

Code: Select all

"Archive Count11"
  $list = runret("C:\Program Files\WinRAR\Rar.exe lt ".quote(<cc_item>));
  $len = strlen($list);
  $newlen = strlen(replace($list, "CRC32:"));
  return ($len-$newlen)/strlen("CRC32:");
Second script is magic, so this is not working for rar:

Code: Select all

$tool = "C:\Program Files\WinRAR\Rar.exe";
    $result = gettoken(trim(runret("""$tool"" lb ""<cc_item>"""), <crlf>), -1, <crlf>);
    return regexmatches($result, "\d+? files?") . " " . regexmatches($result, "\d+? folders?");
    
In both codes need to add rar script + separation: (like in the first post of this topic, 7z can't list rar archives)
1. Rar.exe for *.rar only
2. 7z.exe for *.7z and *.zip only
Last edited by vasya on 06 Feb 2020 18:15, edited 1 time in total.

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Items count for archives zip rar 7z

Post by highend »

Code: Select all

    $ext = gpc(<cc_item>, "ext");
    if ($ext LikeI "rar") {
        $tool   = "D:\Tools\WinRAR\App\WinRAR-x64\Rar.exe";
        $result = gettoken(trim(runret("""$tool"" la ""<cc_item>"""), <crlf>), -1, <crlf>);
        return regexmatches($result, "\d+?$") . " file(s)";
    } else {
        $tool   = "D:\Tools\7-Zip\7za.exe";
        $result = gettoken(trim(runret("""$tool"" l ""<cc_item>"""), <crlf>), -1, <crlf>);
        return regexmatches($result, "\d+? files?") . " " . regexmatches($result, "\d+? folders?");
    }
There is no need to check for .zip;.7z, you can configure the custom column to only take specific file types into account...
One of my scripts helped you out? Please donate via Paypal

vasya
Posts: 57
Joined: 16 Sep 2019 09:18

Re: Items count for archives zip rar 7z

Post by vasya »

highend wrote: 06 Feb 2020 18:15 There is no need to check for .zip;.7z, you can configure the custom column to only take specific file types into account...
Yes, I meant this

Code: Select all

if ($ext LikeI "rar") {
+ Item filter "*.7z;*.zip;*.rar" in the "Configure Custom Column"

Thanks, highend, your code is working excellent
fishgod, Thanks for alternative variant

Image

vasya
Posts: 57
Joined: 16 Sep 2019 09:18

Re: Items count for archives zip rar 7z

Post by vasya »

Is rar counts only elements?
Image
maybe for rar -lb key is better, only strings
Image

How to add a separation on files and folders in rar ?

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Items count for archives zip rar 7z

Post by highend »

That's a bad output to parse.

Use la instead and then you can parse it via regex because only folders have "D" in the attributes column...
One of my scripts helped you out? Please donate via Paypal

vasya
Posts: 57
Joined: 16 Sep 2019 09:18

Re: Items count for archives zip rar 7z

Post by vasya »

highend wrote: 06 Feb 2020 18:49 That's a bad output to parse. because only folders have "D" in the attributes column...
Yes, here are two "D"
Image
highend wrote: 06 Feb 2020 18:49 you can parse it via regex
If I still knew how to do it

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Items count for archives zip rar 7z

Post by highend »

"^ ...D..."

regexmatches()
...
One of my scripts helped you out? Please donate via Paypal

vasya
Posts: 57
Joined: 16 Sep 2019 09:18

Re: Items count for archives zip rar 7z

Post by vasya »

Image

v1 items *.rar;*.zip;*.7z

Code: Select all

$ext = gpc(<cc_item>, "ext");
if ($ext LikeI "rar") {
$list = runret("C:\Program Files\WinRAR\Rar.exe" . " lb " . quote(<cc_item>));
return gettoken($list, "count", <crlf>) - 1 . " items"; 
} else {
$list = runret("C:\7-Zip\7z.exe" . " l " . quote(<cc_item>));
return gettoken(gettoken(gettoken($list, 2, "----".<crlf>), 1, <crlf>."----"), "count", <crlf>) . " items";
}
v2 files-folders *.rar;*.zip;*.7z

Code: Select all

$ext = gpc(<cc_item>, "ext");
if ($ext LikeI "rar") {
$list = runret("C:\Program Files\WinRAR\Rar.exe" . " la " . quote(<cc_item>));
$S = 5;
} else {
$list = runret("C:\7-Zip\7z.exe" . " l " . quote(<cc_item>));
$S = 3;
}
$cut = gettoken(gettoken($list, 2, "----".<crlf>), 1, <crlf>."----");
$D=0;$F=0;
foreach($token, $cut, <crlf>) {
$A = gettoken($token, $S, " ");
if strpos($A,"D") == -1 {$F++} else {$D++};
}
return $F files . " " . $D folders;

Post Reply