Page 1 of 1

Quantity of same file on Drive X:

Posted: 14 Nov 2017 10:45
by chincherpa
Hi,

I have a folder with some files on Drive D:.
Now, I need to know of each file, how often it is present in Drive X:.

Same filenames = MATCH!

I thought about a CustomColumn, triggered by click or list (preferred solution, but slower??)
OR
in a result window, similar to the report window.

Maybe like this:

Code: Select all

Filename:       quantity:
image001.jpg     1
image002.jpg     1
image003.jpg     2
image004.jpg     0
How would I do that? :D

Re: Quantity of same file on Drive X:

Posted: 14 Nov 2017 10:50
by highend
That depends. It makes more sense for a single file to just return it's count in that cc when you click
on it.

If you want to do it for all files, just use a script that shows the result in a window...

Re: Quantity of same file on Drive X:

Posted: 14 Nov 2017 10:52
by chincherpa
Ok, but my knowledge is unfortunately insufficient to do so. :)
May be you can give me a hint?

Re: Quantity of same file on Drive X:

Posted: 14 Nov 2017 10:53
by highend
For which of these options?

Re: Quantity of same file on Drive X:

Posted: 14 Nov 2017 10:56
by chincherpa
I choose:
a script that shows the result in a window...
Thank you!

Re: Quantity of same file on Drive X:

Posted: 14 Nov 2017 11:02
by highend
Are your source files all of the same extension?

Re: Quantity of same file on Drive X:

Posted: 14 Nov 2017 11:02
by chincherpa
yes

Re: Quantity of same file on Drive X:

Posted: 14 Nov 2017 11:18
by highend
Something like this should work (and I've created it in a way that the src folder
can contain files with more than one extension as well)...

Code: Select all

    $src = "D:\here are the files we want to check";
    $dst = "X:\";

    // Get all file extensions
    $srcFiles = listfolder($src, , 1+4, <crlf>);
    $extensions = "*" . regexmatches($srcFiles, "\.\w+$", ";*");
    $extMatches = quicksearch($extensions, $dst, , "s");

    // Loop over all src files
    $results = "Quantity:     Filename:<crlf>";
    foreach($item, $srcFiles, <crlf>, "e") {
        $escaped = regexreplace($item, "([\\.+(){\[^$])", "\$1");
        $matches = regexmatches($extMatches, $escaped, , 1);
        $count = gettoken($matches, "count", "|");
        $results = $results . $count . strrepeat(" ", 14 - strlen($count)) . $item . <crlf>;
    }
    text $results;

Re: Quantity of same file on Drive X:

Posted: 14 Nov 2017 11:32
by chincherpa
Works best, thank you!
And thanks for your time!

Re: Quantity of same file on Drive X:

Posted: 14 Nov 2017 12:00
by chincherpa
Could you please explain me these two lines:

Code: Select all

        $escaped = regexreplace($item, "([\\.+(){\[^$])", "\$1");
        $matches = regexmatches($extMatches, $escaped, , 1);

Re: Quantity of same file on Drive X:

Posted: 14 Nov 2017 13:04
by highend
Each file name needs to be escaped so that I can search for it via a regular expression
(it's the fastest method to generate the necessary count) inside the list of all found items

Re: Quantity of same file on Drive X:

Posted: 14 Nov 2018 14:06
by chincherpa
Hi,

exactly 1 year later...

How would be the CustomColumn-solution?

:biggrin: :D

Re: Quantity of same file on Drive X:

Posted: 14 Nov 2018 14:29
by highend

Code: Select all

Snip: CustomColumn 1
  XYplorer 19.30.0025, 14.11.2018 14:28:26
Action
  ConfigureColumn
Caption
  Count
Type
  3
Definition
      $dst = "X:\";
  
      $extMatches = quicksearch("*.<cc_ext>", $dst, , "s");
      $escaped = regexreplace(<cc_name>, "([\\.+(){\[^$])", "\$1");
      $matches = regexmatches($extMatches, $escaped, , 1);
      return gettoken($matches, "count", "|");
Format
  1
Trigger
  2
Item Type
  0
Item Filter
  

Re: Quantity of same file on Drive X:

Posted: 14 Nov 2018 14:33
by chincherpa
Oh, wow,
that was fast!

Thank you highend :)