Page 1 of 1

Items count for archives zip rar 7z

Posted: 06 Feb 2020 16:32
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 ="))

Re: Items count for archives zip rar 7z

Posted: 06 Feb 2020 17:10
by highend
Why don't you use a scripted custom column?

Re: Items count for archives zip rar 7z

Posted: 06 Feb 2020 17:12
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?

Re: Items count for archives zip rar 7z

Posted: 06 Feb 2020 17:21
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 = ");

Re: Items count for archives zip rar 7z

Posted: 06 Feb 2020 17:22
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?");

Re: Items count for archives zip rar 7z

Posted: 06 Feb 2020 17:55
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

Re: Items count for archives zip rar 7z

Posted: 06 Feb 2020 18:15
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...

Re: Items count for archives zip rar 7z

Posted: 06 Feb 2020 18:22
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

Re: Items count for archives zip rar 7z

Posted: 06 Feb 2020 18:36
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 ?

Re: Items count for archives zip rar 7z

Posted: 06 Feb 2020 18:49
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...

Re: Items count for archives zip rar 7z

Posted: 06 Feb 2020 19:03
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

Re: Items count for archives zip rar 7z

Posted: 06 Feb 2020 19:11
by highend
"^ ...D..."

regexmatches()
...

Re: Items count for archives zip rar 7z

Posted: 06 Feb 2020 22:45
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;