Want highlight of longest filenames

Features wanted...
Post Reply
Papoulka
Posts: 455
Joined: 13 Jul 2013 23:41

Want highlight of longest filenames

Post by Papoulka »

I very often need to scan screenfulls of filenames and manually shorten the longest ones. I stop when 6 or so filenames are all the longest, because to improve things further I'd have to edit all of those.

The process has to be manual because so much of it is judgement and preference. Of course I rely on the column width auto-sizing down as I shorten the longest names. BUT it can be difficult in a long list to find the remaining offenders and/or to see when I've reached my goal.

--> SO I would like a facility to "highlight longest filename(s)". When I run that (button or script) it will highlight all files that are currently the longest. Selecting them would be OK too.

Thus if one file is 145 chars and all others are 144 or less, that file would be highlighted. If two files are 145 chars and one is 144, the two 145-char would be highlighted - because I only want the truly longest.

I can eventually do this with a script, but it won't be easy for me. I post it here because (a) Don might think it useful enough to incorporate as a color filter selection [...doubtful] or (b) one of our estimable XY gurus might knock out a few lines showing me the best way to go.

Thanks for any help or ideas

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

Re: Want highlight of longest filenames

Post by admin »

Sort by Len?

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

Re: Want highlight of longest filenames

Post by highend »

Regarding the selection of the longest ones:

Code: Select all

    $list = "";
    $longest = "";
    $files = listpane(, , 1);

    foreach($file, $files) {
        $len = strlen($file);
        $list = $list . $len . "*" . $file . "|";
    }
    $list = formatlist($list, "r");

    foreach($item, $list) {
        $num = gettoken($item, 1, "*");
        if ($num < $lastNum) { break; }
        $lastNum = $num;
        $longest = $longest . gettoken($item, 2, "*") . "|";
    }
    selectitems $longest;
One of my scripts helped you out? Please donate via Paypal

Papoulka
Posts: 455
Joined: 13 Jul 2013 23:41

Re: Want highlight of longest filenames

Post by Papoulka »

Thank you, highend - that was amazingly fast!

Your script shows how to approach this, which is very helpful. It does fail oddly on this test case of three filenames:

06. Corelli_ Concerto minor (Christmas Concerto) Op6 No8_ 1 Vivace - Grave.flac
07. 2. Allegro.flac
08. 3. Adagio - Allegro - Adagio.flac

In this case the script wrongly finds 08 as the longest. If I remove any character from 06 then it (correctly) finds that filename as the longest. Nothing in your script seems length sensitive so maybe it's a delimiter issue; puzzling.

Two notes: All extensions will be the same, in case that matters. Also I see that if there are only two files, this script selects them both. That's not a practical problem of course, just noted.

Thanks again for your help.

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

Re: Want highlight of longest filenames

Post by highend »

I can reproduce neither of your two problems?

06. ...
is always chosen as the only file to select, even if I use only two of named files.

Maybe it's a path issue.

Replace:
$files = listpane(, , 1);

with:
$files = listpane(, , 1+4);

And insert:
text $list;
text $longest;

Before:
selectitems $longest;

Post both lists from the textboxes.
One of my scripts helped you out? Please donate via Paypal

Papoulka
Posts: 455
Joined: 13 Jul 2013 23:41

Re: Want highlight of longest filenames

Post by Papoulka »

Script as modified:

Code: Select all

    $list = "";
    $longest = "";
    $files = listpane(, , 1+4);

    foreach($file, $files) {
        $len = strlen($file);
        $list = $list . $len . "*" . $file . "|";
    }
    $list = formatlist($list, "r");

    foreach($item, $list) {
        $num = gettoken($item, 1, "*");
        if ($num < $lastNum) { break; }
        $lastNum = $num;
        $longest = $longest . gettoken($item, 2, "*") . "|";
    }
  text $list;
  text $longest;
  selectitems $longest;
First Textbox:

80*06. Corelli_ Concerto minor (Christmas Concerto) Op6 No8_ 1 Vivace - Grave.flac|38*08. 3. Adagio - Allegro - Adagio.flac|20*07. 2. Allegro.flac|

Second textbox:

06. Corelli_ Concerto minor (Christmas Concerto) Op6 No8_ 1 Vivace - Grave.flac|

Thanks. [Also, please check your Paypal acct where an appreciation to highend should soon appear.]

Papoulka
Posts: 455
Joined: 13 Jul 2013 23:41

Re: Want highlight of longest filenames

Post by Papoulka »

And, I didn't notice, the script now runs OK at least on these files... Will try more.

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

Re: Want highlight of longest filenames

Post by highend »

And, I didn't notice, the script now runs OK at least on these files..
Yeah, the output looks as expected :)
Also, please check your Paypal
Thanks :beer:
One of my scripts helped you out? Please donate via Paypal

Enternal
Posts: 1174
Joined: 10 Jan 2012 18:26

Re: Want highlight of longest filenames

Post by Enternal »

Sorry I have not been here in a long time since I'm very busy so I am rusty. But I thought you could highlight long filenames using the color filter:
len:>256
Or am I missing something here? In your case, you would replace 256 with 144. Sorry if I'm misunderstanding something which I may be since I have been operating on about 4 hours of sleep in the last week.

Malarki
Posts: 109
Joined: 03 Dec 2019 02:51

Probable bug in formatlist()

Post by Malarki »

The above script fails when there are filenames greater than 100 char. In that case formatlist($list, "r") doesn't sort the numbered list correctly, so I think this is a bug in that command. I'm not certain because maybe that command never expected to deal with asterisks. But it works on shorter sets of filenames.

Also I think the "break" command should be "continue 2". Otherwise it quits right through the whole IF structure. Not sure of that either since I noted it while still confused by the formatlist() output in my case.

jupe
Posts: 2757
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Want highlight of longest filenames

Post by jupe »

The issue isn't with the asterisk, its that sorting when the digits amount changes 1>2>3 etc doesn't work in some formatlist modes, eg. it works in natural mode, not others. So one workaround for this particular case would be natural sort, then afterwards reverse list, mode v.

Malarki
Posts: 109
Joined: 03 Dec 2019 02:51

Re: Want highlight of longest filenames

Post by Malarki »

Thanks, Jupe, that works well. Now I've got the script selecting the longest filename.

BTW is there a simple way to make that scroll into visibility (I have hundreds of files)?

[Edit: an up-arrow followed by down-arrow does it manually]
Last edited by Malarki on 30 Nov 2021 06:37, edited 1 time in total.

jupe
Posts: 2757
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Want highlight of longest filenames

Post by jupe »

Just add #1049; as the last line.

Malarki
Posts: 109
Joined: 03 Dec 2019 02:51

Re: Want highlight of longest filenames

Post by Malarki »

Thanks for solving all the problems. Now it's just what I needed.

Post Reply