Page 1 of 1
Set filename second increment as 'file-2' not 'file-01-01'?
Posted: 17 Mar 2013 12:35
by robfawcett
If I copy a file called 'file.???' then paste to same folder I get 'file-01.???'. This is great.
I know that if I pasted three times I'd get 'file-02.???', 'file-03.???' - but I never work this way!
If I copy 'file-01.???' then paste to same folder I get 'file-01-01.???'. I'd rather get 'file-02.???' under such circumstances, due to the way my workflow is structured.
Is there any option to always increment the trailing digit?
Can one opt to append date/time instead?
I've read documentation which seems relevant to this but can't actually figure out if exactly what I want is possible...
Many thanks.
Re: Set filename second increment as 'file-2' not 'file-01-0
Posted: 17 Mar 2013 23:58
by Borut
Hello and welcome!
Here is another thread which I believe is on the same topic:
http://www.xyplorer.com/xyfc/viewtopic.php?f=2&t=9178
I do not think it will help you, however (which I regret too, actually). However, I think one has to admit that a general solution to this wish seems to be a rather complex programming problem.
Re: Set filename second increment as 'file-2' not 'file-01-0
Posted: 18 Mar 2013 13:08
by admin
Borut wrote:However, I think one has to admit that a general solution to this wish seems to be a rather complex programming problem.
No, not a rather complex programming problem, but impossible. There is not way to decide whether something is an increment or part of a filename.
Re: Set filename second increment as 'file-2' not 'file-01-0
Posted: 18 Mar 2013 14:08
by robfawcett
I understand the problem, but what if it could be done without having to rely on an algorithm?
What about something like 'Paste Special' → 'Paste Incremented': which would simply parse out the trailing number in the filename and replace it incremented in the name of the duplicate file. It would be a shortcut I'd find very time-saving!
Apologies for not spotting the prior thead - I did try a few likely searches before starting a new one,
Many thanks,
Rob
London
Re: Set filename second increment as 'file-2' not 'file-01-0
Posted: 18 Mar 2013 15:17
by highend
A little script...
Code: Select all
$item = "<curitem>";
$lastDigit = gettoken(regexmatches(getpathcomponent($item, "base"), "\d+", "|"), 1, "|");
if ($lastDigit != "") {
$format = strlen($lastDigit);
$i = 1;
while(true) {
$newDigit = format($lastDigit + $i, strrepeat("0", $format));
$newBaseName = replace($item, $lastDigit, $newDigit);
if (exists($newBaseName) == 0) {
break;
}
$i++;
}
copyitem $item, $newBaseName;
}
It takes the current selected item and duplicates it.
The last found digit in that filename (only base, no extension) is incremented and the while loop checks if the file should be created.
If you have a filename like:
file02-rev3.02.txt
The script will fail (because the replace() command can't replace from the end of a string...).
If you have the files:
file-01.txt
file-02.txt
and you use the script, it will create:
file-03.txt
I haven't included any logic to apply the first numbered extension (-01) so you should still use the normal copy process to create that file. If you want to duplicate that one, you can use this script...
Re: Set filename second increment as 'file-2' not 'file-01-0
Posted: 18 Mar 2013 17:33
by robfawcett
Thank you very much for taking the time to put together a script for me. I'm afraid I'm new to scripting in XYplorer so am actually struggling with it.
I could make a couple of the basic XYplorer demo scripts work, but this one crashed the program for me. I realise that this is likely me being clueless and would be glad of help.
Also, once working, I'm not clear how to make this a quick shortcut to apply to a target file - though I get the impression it's possible.
Thanks again...
Re: Set filename second increment as 'file-2' not 'file-01-0
Posted: 18 Mar 2013 17:52
by highend
but this one crashed the program for me
A crash looks like? It works fine on my PC...
this a quick shortcut to apply to a target file
E.g. by pressing Ctrl + Alt + F9 (opens the Manage User-Defined Commands window),
"Load Script File" (on the left side), and after suplying a caption and the path of the script file, you can assign a keyboard shortcut to it...
Btw, I've made a minor change to the script in my last post. Please use that version.
Re: Set filename second increment as 'file-2' not 'file-01-0
Posted: 18 Mar 2013 18:05
by j_c_hallgren
robfawcett wrote:I'm afraid I'm new to scripting in XYplorer so am actually struggling with it.
Here's a couple of threads that may help get you started:
http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=6560
http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=5750
Re: Set filename second increment as 'file-2' not 'file-01-0
Posted: 18 Mar 2013 20:06
by robfawcett
I really appreciate the help. I'll read those recommended threads.
Thus far;
I followed highend's instructions via Ctrl-Alt-F9
Allocated script to hotkey
Highlighted an arbitrary file called 'Textfile-01.txt' in XYplorer (not sure if this is what I should do?)
Hit my chosen hotkey
XY statusbar says: UDC: load Script File | Increment
Cursor locks to hourglass, XY window title bar adds: (Not Responding)
Have to kill app via taskmngr.
Windows 7 - 32 bit btw
Thank you!
Re: Set filename second increment as 'file-2' not 'file-01-0
Posted: 18 Mar 2013 20:12
by highend
Code: Select all
$item = "<curitem>";
$lastDigit = gettoken(regexmatches(getpathcomponent($item, "base"), "\d+", "|"), 1, "|");
if ($lastDigit != "") {
$format = strlen($lastDigit);
$i = 1;
step;
while(true) {
$newDigit = format($lastDigit + $i, strrepeat("0", $format));
$newBaseName = replace($item, $lastDigit, $newDigit);
if (exists($newBaseName) == 0) {
break;
}
$i++;
}
copyitem $item, $newBaseName;
}
Use this one. Does it work? If not, does it execute the while loop more than once?
Btw, on which XYplorer version are you?
Re: Set filename second increment as 'file-2' not 'file-01-0
Posted: 18 Mar 2013 21:15
by robfawcett
highend,
I'm using ver 11.90.0100
Stepping through the script it seems to be in an increment loop - I never reach an end but see an integer going up 1,2,3,4,5,6,7...
Thank you,
Rob
Re: Set filename second increment as 'file-2' not 'file-01-0
Posted: 18 Mar 2013 21:54
by highend
Update to the latest v12 version, please.
Re: Set filename second increment as 'file-2' not 'file-01-0
Posted: 19 Mar 2013 10:29
by robfawcett
Will do! Busy day - or two - but 'I'll Be Back'...
Thank you,
Rob
Re: Set filename second increment as 'file-2' not 'file-01-0
Posted: 25 Mar 2013 08:54
by robfawcett
I'm back - I'm updated - it's working!
Sincere thanks, particularly, of course, to highend...