"Item Count" property for CCs?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: "Item Count" property for CCs?

Post by TheQwerty »

I would think ListFolder would be a bit quicker for counting items:

Code: Select all

$d = GetToken(ListFolder("<cc_item>", '*', 2), 'Count', '|'); // Directory count.
$f = GetToken(ListFolder("<cc_item>", '*', 1), 'Count', '|'); // File count.
return "$d Dirs, $f Files";
Snippet:

Code: Select all

Snip: CustomColumn 1
  XYplorer 13.90.0000, 3/31/2014 3:01:45 PM
Action
  ConfigureColumn
Caption
  Item Count
Type
  3
Definition
  $d = GetToken(ListFolder("<cc_item>", '*', 2), 'Count', '|'); // Directory count.
  $f = GetToken(ListFolder("<cc_item>", '*', 1), 'Count', '|'); // File count.
  return "$d Dirs, $f Files"
Format
  0
Item Type
  1
Item Filter
 
[/size]There's no need to check <cc_isfolder> since you can just set the column's item type setting to Folders only - which should give a nice speed boost since XY won't have to run the script at all on Files.


Likewise, there's no need to use regexreplace with FolderReport to get extensions - just use the template value:

Code: Select all

$sep = '; '; // Separator to use in the list.
$f = FolderReport('files:{ext}', 'r', "<cc_item>",,,$sep); // List of extensions.
$n = GetToken($f, 'Count', $sep); // Count of files.
if ($n < 1) {
  return "F: 0"; // If no files omit extensions.
} else {
  $f = FormatList($f, 'dnts', $sep); // Clean up extension list.
  if ($f Like "$sep*") { $f = "<none>$f"; } // If the first item is empty add some text for non-extensions.
  $f = FormatList($f, 'e', $sep); // Remove all empties now that the first is changed.
  return "$f, F: $n";
}
Snippet:

Code: Select all

Snip: CustomColumn 1
  XYplorer 13.90.0000, 3/31/2014 3:09:11 PM
Action
  ConfigureColumn
Caption
  Contained Extensions
Type
  3
Definition
  $sep = '; '; // Separator to use in the list.
  $f = FolderReport('files:{ext}', 'r', "<cc_item>",,,$sep); // List of extensions.
  $n = GetToken($f, 'Count', $sep); // Count of files.
  if ($n < 1) {
    return "F: 0"; // If no files omit extensions.
  } else {
    $f = FormatList($f, 'dnts', $sep); // Clean up extension list.
    if ($f Like "$sep*") { $f = "<none>$f"; } // If the first item is empty add some text for non-extensions.
    $f = FormatList($f, 'e', $sep); // Remove all empties now that the first is changed.
    return "$f, F: $n";
  }
Format
  0
Item Type
  1
Item Filter
  
[/size]


To use the above snippets:
  1. Copy the above to your clipboard.
  2. Open the Configure Custom Column dialog
  3. Right-Click the Clear button.
  4. Select Paste Snippet.
  5. OK
HTH

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

Re: "Item Count" property for CCs?

Post by admin »

TheQwerty wrote:Don, shame these snippets do not seem to work with the Snippet SC. :(
For this they would need a reference as to which of the 32 CC definitions should be set. Difficult to share among users...

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

Re: "Item Count" property for CCs?

Post by TheQwerty »

admin wrote:
TheQwerty wrote:Don, shame these snippets do not seem to work with the Snippet SC. :(
For this they would need a reference as to which of the 32 CC definitions should be set. Difficult to share among users...
Why don't we have this same issue with CTBs?

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

Re: "Item Count" property for CCs?

Post by admin »

Uhm... I'll tell you tomorrow... :biggrin:

PeterH
Posts: 2828
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: "Item Count" property for CCs?

Post by PeterH »

admin wrote:
PeterH wrote:By the way: in help:

- gettoken() shows all operands as quoted - in Syntay as well as in Examples, while
- gettokenindex() shows operands quoted in Examples, while in Syntax separator and flags are shown unquoted...
(Sometimes users use a strange way of quoting :whistle: )
Well, I think that's okay to show it unquoted in the syntax. Saves space, and ultimately the climate.
Sorry - I've missed this reply :oops:

And sorry, but in terms of quoting the Syntax-Definition
gettokenindex(token, tokenlist, [separator=|], [flags=iw]);
is just wrong. And people will (sometimes) use it as a model.
And it (sometimes) will lead people to learn bad/wrong quoting...
(Yes: they *might* read the examples :roll: )

Just my opinion.

Funny - with
gettoken(string, [index=1], [separator=" "], [format], [flags])
you made it correct for separator :biggrin: :lol: :wink:

yusef88
Posts: 1148
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Re: "Item Count" property for CCs?

Post by yusef88 »

TheQwerty wrote:I would think ListFolder would be a bit quicker for counting items:

Code: Select all

$d = GetToken(ListFolder("<cc_item>", '*', 2), 'Count', '|'); // Directory count.
$f = GetToken(ListFolder("<cc_item>", '*', 1), 'Count', '|'); // File count.
return "$d Dirs, $f Files";
To see the attached files, you need to log into the forum.

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

Re: "Item Count" property for CCs?

Post by TheQwerty »

yusef88 wrote:<notihng but an image>
Did you configure the column correctly?

yusef88
Posts: 1148
Joined: 28 Jan 2013 03:50
Location: Windows 8.1 32-bit

Re: "Item Count" property for CCs?

Post by yusef88 »

i guess yes
happens when show hidden system folder
To see the attached files, you need to log into the forum.

SkyFrontier
Posts: 2341
Joined: 04 Jan 2010 14:27
Location: Pasárgada (eu vou!)

Re: "Item Count" property for CCs?

Post by SkyFrontier »

@TheQwerty

Hi!
Thanks for the pointers. The listfolder() method seems to be a bit faster, but I'm yet to find a machine processing templates fast enough: in the same backup folder I was operating, your version froze XY instance for almost 50 secs against 10 from my original script. At first I thought it was recursing the whole subfolders structure, but it's not. On the other hand, it seems to avoid a problem I had with files without a extension. Have to study this.

Yes, I'm learning some tricks to reduce operations to a minimum as CCs demand some care to not interfere on list browsing. I'm even appealing to nesting operations. It's not didactic at all, but seems to be a way to minimize impact on performance.
New User's Ref. Guide and Quick Setup Guide can help a bit! Check XYplorer Resources Index for many useful links!
Want a new XYperience? XY MOD - surfYnXoard
-coz' the aim of computing is to free us to LIVE...

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

Re: "Item Count" property for CCs?

Post by admin »

admin wrote:Uhm... I'll tell you tomorrow... :biggrin:
OK, SC snippet will work with Custom Column snippets in next version. It will find the next undefined column and define it. Undocumented. Snippets are officially still *planned*. :biggrin:

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

Re: "Item Count" property for CCs?

Post by TheQwerty »

yusef88 wrote:i guess yes
happens when show hidden system folder
Indeed... Looks like a fundamental difference between ListFolder and FolderReport. The former shows error dialogs and the latter returns an empty string, so unfortunately neither can get you 100% of the way there. At least FolderReport is more graceful when it fails.

Post Reply