Want highlight of longest filenames
Want highlight of longest filenames
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
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
Re: Want highlight of longest filenames
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
Re: Want highlight of longest filenames
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.
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.
Re: Want highlight of longest filenames
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.
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
Re: Want highlight of longest filenames
Script as modified:
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.]
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;
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.]
Re: Want highlight of longest filenames
And, I didn't notice, the script now runs OK at least on these files... Will try more.
Re: Want highlight of longest filenames
Yeah, the output looks as expectedAnd, I didn't notice, the script now runs OK at least on these files..
ThanksAlso, please check your Paypal
One of my scripts helped you out? Please donate via Paypal
Re: Want highlight of longest filenames
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:
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.len:>256
Probable bug in formatlist()
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.
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.
Re: Want highlight of longest filenames
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.
Re: Want highlight of longest filenames
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]
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.
Re: Want highlight of longest filenames
Just add #1049; as the last line.
Re: Want highlight of longest filenames
Thanks for solving all the problems. Now it's just what I needed.