c:\parent\child.ext > c:\parent\parent.child.ext

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
Dramastic
Posts: 8
Joined: 21 Mar 2008 20:58

c:\parent\child.ext > c:\parent\parent.child.ext

Post 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

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Post 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...
Proud XYplorer Fanatic

serendipity
Posts: 3360
Joined: 07 May 2007 18:14
Location: NJ/NY

Post 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.

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Post 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!
Proud XYplorer Fanatic

Dramastic
Posts: 8
Joined: 21 Mar 2008 20:58

Nice!! Almost there now..

Post 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

Dramastic
Posts: 8
Joined: 21 Mar 2008 20:58

No such luck

Post 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

j_c_hallgren
XY Blog Master
Posts: 5826
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL
Contact:

Re: No such luck

Post 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).
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.

RalphM
Posts: 2086
Joined: 27 Jan 2005 23:38
Location: Cairns, Australia

Post 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
Ralph :)
(OS: W11 25H2 Home x64 - XY: Current x64 beta - Office 2024 64-bit - Display: 1920x1080 @ 125%)

admin
Site Admin
Posts: 66083
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Post by admin »

RalphM wrote:Hope this helps
Yes, and I'd like to know if it did.

RalphM
Posts: 2086
Joined: 27 Jan 2005 23:38
Location: Cairns, Australia

Post 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?
Ralph :)
(OS: W11 25H2 Home x64 - XY: Current x64 beta - Office 2024 64-bit - Display: 1920x1080 @ 125%)

Dramastic
Posts: 8
Joined: 21 Mar 2008 20:58

Post 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

Post Reply