Page 1 of 1
c:\parent\child.ext > c:\parent\parent.child.ext
Posted: 21 Mar 2008 21:07
by Dramastic
I really need to rename a huge number of files such as
c:\grandparent\parent\child.ext
c:\dir1\dir2\dir3\file.ext
to the new format
c:\grandparent\parent\grandparent.parent.child.ext
c:\dir1\dir2\dir3\dir1.dir2.dir3.file.ext
I apologize if someone has previously asked this question before. I did try to search through the forums for about 30 minutes without finding any solutions before posting this. I'm guessing its a pretty common question though.
Can this presently be done with XYPlorer?
P.S. Looks like you guys have a very active community here. Hopefully when I get some more free time I'll be able to read up on the forums a bit more.
Dramastic
Posted: 21 Mar 2008 22:14
by jacky
Welcome to the world of XY!
Well, I'm not sure this is such a common question actually... Anyway, it seems a little tricky because it uses the full path on a file to determine its new name, but a script like this should do it :
Code: Select all
// Get full path\name.ext
set $name, <curitem>;
// Remove drive (D:\)
substr $name, $name, 3;
// Replace \ by .
replace $name, $name, "\", ".";
// Rename the file
rename ,"$name/e";
Just put that in a UDC (menu User/Manage Commands) under "Run Script", assign a KS to it, and you'll just need to press one key to rename a file as you want.
Note that it does only work for one file ata time though, you can't select a bunch of them and have them all renamed at once. I'm not sure if that would be possible with another script...
Posted: 21 Mar 2008 22:20
by serendipity
I am not sure but maybe:
::substr $p, <curpath>, 3;replace $p, $p, "\", "."; copytext $p; rename bat, $p*
I tried from AB and it worked.
Since i am not sure, use with caution
BTW: part of it was copied from
http://88.191.26.34/XYwiki/index.php/Sc ... nd:_substr
thanks to jacky.
Posted: 21 Mar 2008 23:44
by jacky
serendipity wrote:::substr $p, <curpath>, 3;replace $p, $p, "", "."; copytext $p; rename bat, $p*
Oh yeah, didn't think of that. That's a pretty nice script actually, and that should work for groups of files (as long as they are on the same folders, but that's probably usually the case)
I think it should adjusted just a little:
Code: Select all
substr $p, <curpath>, 3; replace $p, $p, "", "."; rename bat, "$p.*";
(I only removed the copytext, useless here I believe, and added a missing dot in the rename pattern.
Nice one serendipity!
Nice!! Almost there now..
Posted: 22 Mar 2008 00:34
by Dramastic
Very nice you guys!
Now if there is just some sort of "for each" script command (as in for each subdirectory) I can wrap around it and recurse the tree with I will be set.
Perhaps there is a tree-walking script somewhere on the forum already.. I'll look around and see..
Dramastic
No such luck
Posted: 22 Mar 2008 06:22
by Dramastic
No such luck.
As much as I really like XYPlorer, it seems it does not yet do conditional statements either.
I tried to overcome all of this by using the powerful "find" features to make a list out of all the files I wanted to rename first, and then running variations on the above provided samples to see if I could get it to work. Unfortunately not. The variables like <curpath><curitem> etc. seem to be updated only on the very first of the renames, and so all the other renamed files end up with the same prefix instead of their own.
I really thought I was onto somethng with code like:
Code: Select all
substr $p, <focitem>, 3; replace $p, $p, "\", "."; rename bat, $p; sel +1; sub;
Until I discovered there are no "while" "do until" "for each" "if then" or other conditional statements available to break the recursive sub loop.
That seems to pretty much leave the regex comparison capabilities plus the increment capability, but I'm not even sure how I would get the count of files in the list window.
Anyway I will keep an eye on this software - its actually my second time evaluating it in the last few years (this time on the new version 6), and it seems to be getting better and better. Keep it up and it will be a full fledged file-system-interface programming-language in no time!
I'll keep an eye on this thread too incase someone comes up with a complete solution to this task.
Thanks for all the effort and help on this guys!
Dramastic
Re: No such luck
Posted: 22 Mar 2008 07:40
by j_c_hallgren
Dramastic wrote:No such luck.
As much as I really like XYPlorer, it seems it does not yet do conditional statements either.
----
I'll keep an eye on this thread too incase someone comes up with a complete solution to this task.
Thanks for all the effort and help on this guys!
While XY doesn't yet do loops or conditionals, I'd kinda suspect it shouldn't be too far down the road, so if you've not bought it, you may want to do so now at the current pricing instead of waiting...
Plus, given that you've had a need for this already, you could help in the development which is another benefit to you (and us).
Posted: 25 Mar 2008 00:07
by RalphM
If you rename files only in one folder at a time, there's no need for loops, since rename handles multiple files in one go.
I tested the following script successfully with multiple files selected in ONE folder only (i.e. no search results spanning multiple locations)
Code: Select all
//Get current path & strip off drive letter
substr $path, <curpath>, 3;
//Replace \ by .
replace $path, $path, "\", ".";
//Regexp rename (capture current filename for later usage with "$1"-syntax
rename re, (^.*) > $path.$1, p
With the preview option (p) you even get a list, showing the old and new filenames side by side, with the ability to accept or cancel the rename (and the script as well) without doing any harm to your files.
Hope this helps
Posted: 28 Mar 2008 20:17
by admin
RalphM wrote:Hope this helps
Yes, and I'd like to know if it did.
Posted: 29 Mar 2008 01:06
by RalphM
admin wrote:RalphM wrote:Hope this helps
Yes, and I'd like to know if it did.
Me too actually. I was wondering whether Dramastic ever came back and read this?
Posted: 29 May 2008 00:31
by Dramastic
Reading it now..
Its been a couple months, so I thought I would check in to see how the software has developed. I'm downloading the latest version now, and I will see whats new and whether this is possible now.
Regarding the suggestion to do one folder at a time, I'm afraid that would defeat the purpose - then I could simply pre-pend the same string constant to all files in a given folder. In my case at least there are thousands of folders with only a few files in each.
Dramastic