Page 1 of 2
Rename current item with name of current folder
Posted: 07 Apr 2008 21:10
by jacky
Just a little script that will rename the current item to the name of the current folder, eg. if you're in "D:\Program Files\XYplorer" then the file's new name would be "XYplorer"
Code: Select all
regexreplace $name, <curitem>, "^.+\\([^\\]+?)\\[^\\]+?.*$", "$1";
rename bat, $name;
Note that the extension remains unchanged. If you want to remove it, or always use one, simply change the second line to something like this:
Posted: 08 Apr 2008 01:20
by lem
AWESOME - thank you - perfect timing on this. I knew it was possible to do this now with scripting and was going to try and figure this out to get my feet wet as I've always wanted this command. Lo and behold, go looking for it today and you just posted it a few hours ago. Thanks again for sharing.
Re: Rename current item with name of current folder
Posted: 09 Apr 2008 07:36
by admin
jacky wrote:Code: Select all
regexreplace $name, <curitem>, "^.+\\([^\\]+?)\\[^\\]+?.*$", "$1";
rename bat, $name;
Same but shorter, and also works in drives roots (sets name to [drive letter].ext):
Code: Select all
set $name, <curfolder>;
rename , $name;
Posted: 09 Apr 2008 12:46
by jacky
Yep, that's a much better solution. I have to say, before I read your post, I didn't about about <curfolder>

I mean, I'm sure I did at some point, but I had completely forgotten about it!
Good one, thanks

Posted: 09 Apr 2008 12:56
by ivan
"If it's not broken, then don't fix it" philosophy falls on death ears. "If it's not perfect, then keep improving" rules ftw!

Posted: 09 Apr 2008 13:19
by jacky
PS: btw you can make it even shorter, of course:
Posted: 09 Apr 2008 14:10
by admin
jacky wrote:PS: btw you can make it even shorter, of course:
Ahhhhhh.

Hey, that XY proggy with that scripting stuff really rocks...
Posted: 09 Apr 2008 22:13
by ivan
jacky wrote:PS: btw you can make it even shorter, of course:
It must be noted that this script doesn't result in the same renaming result as the one posted in the first post if there are files that have the same name but different extension in the same folder.
Posted: 10 Apr 2008 15:15
by ivan
Just as a follow up, is there any way to modify your original (long

) script to specify how the file should be suffixed if the same file already exists? Thanks a lot

Posted: 10 Apr 2008 16:48
by jacky
I think both scripts should result in the same thing, and both use number suffix in case of collision. You can define the format used for that suffix on Configuration - Report : Filename templates
Posted: 10 Apr 2008 17:09
by ivan
And what if I wanted that "suffix" to be just before a certain symbol at the end of a filename (the symbol is a dash if it helps)?
EDIT: I guess what I'm asking is: is it possible for a script to override a preference?
The logic behind it is that a person may not be aware of a preference or needs it tweaking a little.
Posted: 10 Apr 2008 22:17
by admin
ivan wrote:And what if I wanted that "suffix" to be just before a certain symbol at the end of a filename (the symbol is a dash if it helps)?
EDIT: I guess what I'm asking is: is it possible for a script to override a preference?
The logic behind it is that a person may not be aware of a preference or needs it tweaking a little.
Good point. You will get that with the next beta release.
Code: Select all
E.g., to name items as their containing folder while having full
control over the number suffix format and start number, you now
can use any of these scripts without fearing collisions:
::rename , <curfolder>-<#001>, p;
::rename , <curfolder>-<#00001>, p;
::rename , <curfolder>-<#23>, p;
This works already today, but collisions with existing files are possible.
Posted: 25 Jul 2008 16:52
by ivan
admin wrote:Good point. You will get that with the next beta release.
But is it still possible to disable scripts overriding through a preference? Methinks it's not so can we please have some balance so if a script can override a preference then a preference should be able to overpower whether a script is able to stomp all over a preference. I hope I'm making some sense

Posted: 25 Jul 2008 20:57
by admin
ivan wrote:admin wrote:Good point. You will get that with the next beta release.
But is it still possible to disable scripts overriding through a preference? Methinks it's not so can we please have some balance so if a script can override a preference then a preference should be able to overpower whether a script is able to stomp all over a preference. I hope I'm making some sense

No. Try again, please.
Posted: 25 Jul 2008 21:07
by eurytos
admin wrote:ivan wrote:admin wrote:Good point. You will get that with the next beta release.
But is it still possible to disable scripts overriding through a preference? Methinks it's not so can we please have some balance so if a script can override a preference then a preference should be able to overpower whether a script is able to stomp all over a preference. I hope I'm making some sense

No. Try again, please.
I *think* he was trying to say that he wants to be able to choose whether a preference can be overwritten by a script.
something like:
preference one: script can overwrite
preference two: do not allow script to overwrite
I could be way off though...