Page 1 of 1

Rename with sequence number (based on existing files)

Posted: 27 May 2008 14:00
by pmoore
I have a set of folders where files are named with a numeric sequence suffix -

1.First file.msg
2.Second file.msg
...etc

What I want to do is when I add new files to the folder, select them and rename them with ascending sequence numbers (which I know I can do with smart rename) but starting with the first unused sequence.

So, in the above case, if I add a third file, it would be renamed as 3.Whatever.txt.

Is this possible? If not, is it something that could be considered as a plausible feature request?

Thanks,
Paul.

Posted: 27 May 2008 21:45
by jacky
Well, that's not a feature no, but you can probably work it out using a script.

For example, this should rename the current item by prefixing it with a number and a dot, starting at the next number available.
(Note that it only works with one file at a time.)

Code: Select all

 set $name, <curname>;
 sortby "Name",d;
 filter ">^[0-9]+\..+$";
 sel 1,1;
 regexreplace $nb, <curbase>, "^([0-9]+)\..+$", "$1";
 incr $nb;
 filter;
 sortby "Name",a;
 sel 1,0;
 sel "[$name]";
 rename ,"$nb.*";

Posted: 27 May 2008 22:09
by TheQwerty
Hmmm.. I'm confused.

Isn't this what the "/s" switch is supposed to accomplish?
http://www.xyplorer.com/xyfc/viewtopic. ... 2119#22119
http://88.191.26.34/XYwiki/index.php/Re ... Collisions

Posted: 28 May 2008 11:44
by jacky
Well, no, but batch Rename yes. Thing is, and I think I must've been too tired to see what I was doing, but yesterday I tried thinking that how Batch Rename works, and it didn't. So I was confused but just went away with it... turns out stupid me used this as pattern: "1.*" instead of "<#1>.*" ! :roll: :oops:

So, yeah... But you still need to use a script to find out the number to start at, because BR (/s or not) checks against the full "destination" filename, so using "<#1>.*/s" will not work, because while there might be a "1.foo.txt" there is not a "1.bar.txt", so it will not move the increment to 2 !

So "now" that we can have it work with multiple files, maybe something like this would be better:

Code: Select all

 // Open New Tab
 #340;
 sortby "Name",d; 
 filter ">^[0-9]+\..+$"; 
 sel 1,1; 
 regexreplace $nb, <curbase>, "^([0-9]+)\..+$", "$1"; 
 incr $nb; 
 // Close Tab
 #351;
 rename ,"<#$nb>.*";
This will create a new tab, selection is preserved, filter/re-order it to get the last number used, then close the tab (whre selection should be preserved as well) and do a BR as expected.

Please note that there's a limitation to selection being preserved. I haven't checked, but I think they might only be preserved when less than 255 items are selected, so be aware of that limit.

Am I right now, or still missing something obvious?

Posted: 28 May 2008 13:35
by TheQwerty
jacky wrote:... because BR (/s or not) checks against the full "destination" filename, so using "<#1>.*/s" will not work, because while there might be a "1.foo.txt" there is not a "1.bar.txt", so it will not move the increment to 2 !
Indeed, I wasn't thinking about the fact that everything following the number could still differ and thus may not collide. :oops:

Posted: 29 May 2008 13:03
by pmoore
jacky wrote: So "now" that we can have it work with multiple files, maybe something like this would be better:
Thanks, that looks fantastic! I'll give it a go.

Paul.