Select files with same name pattern as selected

Features wanted...
Reve_Etrange
Posts: 91
Joined: 19 Mar 2008 18:15

Select files with same name pattern as selected

Post by Reve_Etrange »

I have a secret to share with you guys.

Sometimes I have many files with the same name pattern, most often parts of an archive like:
chubbymaid.part1.rar
chubbymaid.part2.rar
...
chubbymaid.part497.rar
(yeah, big files obviously)

What would be cool is some right-click menu when part1 is selected so as to select all the other parts of the gorgeous, lovely archive.

I know I could go with visual filters and likes, but there are times when you shouldn't make a lady wait.

Thank you for your kind attention.

highend
Posts: 13313
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Select files with same name pattern as selected

Post by highend »

Make a simple script and a user command / toolbar button / catalog entry?

Hints:

folderreport() to give you the list of all files with ".part" in it.

delete selection.

Done.
One of my scripts helped you out? Please donate via Paypal

Reve_Etrange
Posts: 91
Joined: 19 Mar 2008 18:15

Re: Select files with same name pattern as selected

Post by Reve_Etrange »

Looks like a solution, but scripting is a daunting task for a humble lvl2 apprentice like me.
And I have often have many unrelated files with 'part' in it, dunno if it would be an issue.

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Select files with same name pattern as selected

Post by Stefan »

Hi Reve,

i think CTRL+M or CTRL+J is the way to go.

Or like highend suggested use an script like this below

to help you preparing the wanted pattern, because the
selected file name is already in the dialog for you to modify:

Code: Select all

 $f = input( "Modify and leave wanted parts of file name only<crlf>
               to select all other files with same part too. <crlf>
               Tip: use empty filter to disable filter again", "<curname>", "<curname>");

  if ($f != ""){
     //filter for user pattern, (show matching files only):
       filter "*$f*";

     //select all (visible/filtered) files:
       sel "a";

     //disable filter to show all files again (selected and un-selected):
       filter;
  }
  else{
      //deselect all:
        sel;
  }
XYplorer_SelectByNamepart.png
XYplorer_SelectByNamepart.png (18.95 KiB) Viewed 2279 times

Reve_Etrange
Posts: 91
Joined: 19 Mar 2008 18:15

Re: Select files with same name pattern as selected

Post by Reve_Etrange »

Thank you, I somehow managed to save your script and create a catalog entry for it. Appreciate it.

You seem fluent in XY scripting, so do you know if it is possible to automatically discard the final /\n+\.rar/ from the filename?
So that running the script with 'chubbymaid.part1.rar' selected would pop up the dialog already filled with 'chubbymaid.part'

highend
Posts: 13313
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Select files with same name pattern as selected

Post by highend »

Replace this:

Code: Select all

$f = input( "Modify and leave wanted parts of file name only<crlf>
               to select all other files with same part too. <crlf>
               Tip: use empty filter to disable filter again", "<curname>", "<curname>");
with:

Code: Select all

 $default = regexreplace("<curname>", "(.+)(\d\..+)", "$1");
 $f = input( "Modify and leave wanted parts of file name only<crlf>
               to select all other files with same part too. <crlf>
               Tip: use empty filter to disable filter again", "<curname>", "$default");
One of my scripts helped you out? Please donate via Paypal

Reve_Etrange
Posts: 91
Joined: 19 Mar 2008 18:15

Re: Select files with same name pattern as selected

Post by Reve_Etrange »

Works, thank you for you help, mate.

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Select files with same name pattern as selected

Post by Stefan »

highend wrote:Replace this:

with:

Code: Select all

 $default = regexreplace("<curname>", "(.+)(\d\..+)", "$1");
 

'(.+)' is greedy and will match as many as can get, even digits.
And '\d' will match only one single digit (the last one)

This would resulting in
"chubbymaid.part49"
for
"chubbymaid.part497.rar"


Better would be '(.+?)\d*'
where '(.+)' will stop at first found digit due the '?' modifier
and '\d*' will match none-or-more digits, and
so match even 'part' without any digit. (if wanted. If not, use '\d+' instead as ==> '(.+?)\d+')


- - -
Reve_Etrange wrote: if it is possible to automatically discard the final /\n+\.rar/ from the filename?
So that running the script with 'chubbymaid.part1.rar' selected
would pop up the dialog already filled with 'chubbymaid.part'

Code: Select all

 $f = input( "Modify and leave wanted parts of file name only<crlf>
               to select all other files with same part too. <crlf>
               Tip: use empty filter to disable filter again", "<curname>",
               regexreplace("<curbase>", "(.+?)\d*", "$1"));

  if ($f != ""){
     //filter for user pattern, (show matching files only):
       filter "*$f*";

     //select all (visible/filtered) files:
       sel "a";

     //disable filter to show all files again (selected and un-selected):
       filter;
  }
  else{
      //deselect all:
        sel;
  }

highend
Posts: 13313
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Select files with same name pattern as selected

Post by highend »

Your corrections are right Stefan,

but why should somebody ever select "chubbymaid.part49" to extract a .rar archive (although this is possible) instead of using one of the first 9 files?

But user opinions about file selection / management / tend to differ I suppose xD
One of my scripts helped you out? Please donate via Paypal

Reve_Etrange
Posts: 91
Joined: 19 Mar 2008 18:15

Re: Select files with same name pattern as selected

Post by Reve_Etrange »

Fixed the regexp on my own - I didn't want to nitpick when I had just been given a hand.
For what it's worth I'm happy with /(.+part)\d+\.rar$/

Your suggestion, Stefan, might stumble on something like 'kinkynurse4all.part99.rar' (haven't tested though).

highend
Posts: 13313
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Select files with same name pattern as selected

Post by highend »

Btw, you don't have to use the $ for the end of line (the regex will stop on linebreaks automatically).
One of my scripts helped you out? Please donate via Paypal

Reve_Etrange
Posts: 91
Joined: 19 Mar 2008 18:15

Re: Select files with same name pattern as selected

Post by Reve_Etrange »

Might as well anchor it to the end, in case someone come up with some monsters like 'tear.me.apart1337.rar.part427.rar'
As rhetorical as it gets, but well - doesn't hurt.

Reve_Etrange
Posts: 91
Joined: 19 Mar 2008 18:15

Re: Select files with same name pattern as selected

Post by Reve_Etrange »

I eventually discarded the dialog since I always accept the default choice, but there's still a small annoyance: the listview loses focus and autoscroll so as to put the selection on top.

Are there some commands to fix that?

highend
Posts: 13313
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Select files with same name pattern as selected

Post by highend »

Sorry, didn't understand the explanation.

Mind to post a screenshot and mark what's wrong?
One of my scripts helped you out? Please donate via Paypal

Reve_Etrange
Posts: 91
Joined: 19 Mar 2008 18:15

Re: Select files with same name pattern as selected

Post by Reve_Etrange »

I created a '::load "myfile.xys"' entry in the catalog and I click on it to run the script. Unfortunately, the catalog keeps the focus after I click on it eg. if I press 'delete', it asks for the deletion of the catalog entry, not the selected files.

In addition, if I can see that in the list (selection in blue):
Folder1
Folder2
blonde
brunette
redhead.part1.rar
redhead.part2.rar
redhead.part3.rar
milf
...
and click the catalog entry running the script, I end up seeing:
redhead.part1.rar
redhead.part2.rar
redhead.part1.rar

milf
...
i.e. the list scrolled so that the selected files are now on top, and I must move the scrollbar up so as to see the folders and files above.

Post Reply