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.
Rename with sequence number (based on existing files)
-
pmoore
- Posts: 28
- Joined: 27 May 2008 13:50
-
jacky
- XYwiki Master
- Posts: 3106
- Joined: 23 Aug 2005 22:25
- Location: France
- Contact:
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.)
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.*";Proud XYplorer Fanatic
-
TheQwerty
- Posts: 4373
- Joined: 03 Aug 2007 22:30
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
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
-
jacky
- XYwiki Master
- Posts: 3106
- Joined: 23 Aug 2005 22:25
- Location: France
- Contact:
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>.*" !
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:
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?
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>.*";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?
Proud XYplorer Fanatic
-
TheQwerty
- Posts: 4373
- Joined: 03 Aug 2007 22:30
Indeed, I wasn't thinking about the fact that everything following the number could still differ and thus may not collide.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 !
XYplorer Beta Club