Set filename second increment as 'file-2' not 'file-01-01'?
-
robfawcett
- Posts: 7
- Joined: 17 Mar 2013 12:27
Set filename second increment as 'file-2' not 'file-01-01'?
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.
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.
-
Borut
- Posts: 1472
- Joined: 19 Oct 2010 19:29
- Location: Win10 Pro 64b 22H2, @120DPI (125%)
Re: Set filename second increment as 'file-2' not 'file-01-0
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.
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.
Win 10 Pro 64bit
-
admin
- Site Admin
- Posts: 67229
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Set filename second increment as 'file-2' not 'file-01-0
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.Borut wrote:However, I think one has to admit that a general solution to this wish seems to be a rather complex programming problem.
FAQ | XY News RSS | XY X
-
robfawcett
- Posts: 7
- Joined: 17 Mar 2013 12:27
Re: Set filename second increment as 'file-2' not 'file-01-0
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
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
-
highend
- Posts: 15016
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Set filename second increment as 'file-2' not 'file-01-0
A little script...
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...
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;
}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...
Last edited by highend on 18 Mar 2013 20:13, edited 2 times in total.
One of my scripts helped you out? Please donate via Paypal
-
robfawcett
- Posts: 7
- Joined: 17 Mar 2013 12:27
Re: Set filename second increment as 'file-2' not 'file-01-0
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...
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...
-
highend
- Posts: 15016
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Set filename second increment as 'file-2' not 'file-01-0
A crash looks like? It works fine on my PC...but this one crashed the program for me
E.g. by pressing Ctrl + Alt + F9 (opens the Manage User-Defined Commands window),this a quick shortcut to apply to a target file
"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.
One of my scripts helped you out? Please donate via Paypal
-
j_c_hallgren
- XY Blog Master
- Posts: 5826
- Joined: 02 Jan 2006 19:34
- Location: So. Chatham MA/Clearwater FL
- Contact:
Re: Set filename second increment as 'file-2' not 'file-01-0
Here's a couple of threads that may help get you started:robfawcett wrote:I'm afraid I'm new to scripting in XYplorer so am actually struggling with it.
http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=6560
http://www.xyplorer.com/xyfc/viewtopic.php?f=7&t=5750
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.
-
robfawcett
- Posts: 7
- Joined: 17 Mar 2013 12:27
Re: Set filename second increment as 'file-2' not 'file-01-0
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!
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!
-
highend
- Posts: 15016
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Set filename second increment as 'file-2' not 'file-01-0
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;
}Btw, on which XYplorer version are you?
One of my scripts helped you out? Please donate via Paypal
-
robfawcett
- Posts: 7
- Joined: 17 Mar 2013 12:27
Re: Set filename second increment as 'file-2' not 'file-01-0
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
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
-
highend
- Posts: 15016
- Joined: 06 Feb 2011 00:33
- Location: Win Server 2022 @100%
Re: Set filename second increment as 'file-2' not 'file-01-0
Update to the latest v12 version, please.
One of my scripts helped you out? Please donate via Paypal
-
robfawcett
- Posts: 7
- Joined: 17 Mar 2013 12:27
Re: Set filename second increment as 'file-2' not 'file-01-0
Will do! Busy day - or two - but 'I'll Be Back'...
Thank you,
Rob
Thank you,
Rob
-
robfawcett
- Posts: 7
- Joined: 17 Mar 2013 12:27
Re: Set filename second increment as 'file-2' not 'file-01-0
I'm back - I'm updated - it's working!
Sincere thanks, particularly, of course, to highend...
Sincere thanks, particularly, of course, to highend...
XYplorer Beta Club