Renaming files

A collection of especially useful xplorer² topics and ideas. New users may find it helpful to look here before searching the other forums for information. >>>>>> Please post new material in the relevant forum. (New stuff posted here will be removed.) Thanks. -fg-

Moderators: fgagnon, nikos

User avatar
FrizzleFry
Platinum Member
Platinum Member
Posts: 1142
Joined: 2005 Oct 16, 19:09

Post by FrizzleFry » 2006 Apr 05, 03:30

narayan wrote:One more, please!

Some file names merge all words, but put caps at the beginning of each word. How do I enter a space between those words and then make the first letter capitalized?


Example: HowToFindDuplicates  to How to find duplicates
This one does what you are after but I am not very happy with it:

use locale;$file =~s/([A-Z])/ $1/g;$file =~s/( ?)(.+)/\u\L$2/;

If I come up with a better one I'll post it.

Demetris
Silver Member
Silver Member
Posts: 217
Joined: 2004 Jul 04, 17:18

Post by Demetris » 2006 Apr 05, 06:07

Thanks, FrizzleFry.

narayan
Platinum Member
Platinum Member
Posts: 1430
Joined: 2002 Jun 04, 07:01

Post by narayan » 2006 Apr 15, 03:49

I had observed this earlier, in a single experiment:
It is not slow in my case, but it does require a refresh. The old entries do not vanish--They don't change, either.
I usually rename a large number of files at a time; so I didn't have many occasions to check out the context-menu based working of awxrenamer. But I tried it again today; and found that there is no refresh problem-- x2 shows the changed names immediately.

Any observations about this?
**********

BTW some of the renamers mentioned here (e.g. Lupas Renamer, THE Rename) can change the Explorer/x2 context menu, so that you can highlight the files and send them to the app. The app gets launched and loads the files in its GUI. Now you can do what you want. Of course, it is not as fast as the awxrenamer's context menu.

But I don't know if any renamer except awxrenamer provides such options right in the context menu.

User avatar
FrizzleFry
Platinum Member
Platinum Member
Posts: 1142
Joined: 2005 Oct 16, 19:09

Post by FrizzleFry » 2006 Apr 15, 06:01

The only time I do not get immediate refresh is if I only change case.

There is at least one other renamer that has a configurable context menu:

MRename (http://fly.srk.fer.hr/~rajko/MRename/)

I was using it before I discovered awxRename (thanks BRX!).  The main problem with MRename is that it only supports single character replacement, also its pattern definition is kinda wonky.  Basically you define fields from the original names, then rearrange and adjust the desired fields to create the new names.  It is pretty flexible but it takes some effort to get used to its commands.  I have been using Perl for years so awxRename just feels more intuitive.

narayan
Platinum Member
Platinum Member
Posts: 1430
Joined: 2002 Jun 04, 07:01

Post by narayan » 2006 Apr 15, 07:02

Thanks for that update. Yes, it does not refresh the change case. (This time I didn't try the change case; and so missed that.)

but then when I change case using Lupas Rename also, x2 does not reflect that immediately. Probably Windows plays a hand in that(?)

BTW the first alpha capitalization trick didn't work. Itried with files that starts with a number. Another file has a number and then a hyphen. In both cases, the name didn't change. (I refreshed display in x2, of course)

User avatar
JamieG
Member
Member
Posts: 47
Joined: 2004 Oct 03, 11:43
Location: Paris, France

UnStuddlyCapping

Post by JamieG » 2006 Apr 15, 10:23

Oh that's easy, Narayan! :biggrin:

If one's using perl REs, one needs to do a zero-length negative look-behind assertion to get past an initial upper-cased letter (to avoid putting a space at the start of the string), and then replace any cap with itself preceded by a space.  The following:

           s/(?<!^)([A-Z])/ $1/g

will turn x2MagicManual into x2 Magic Manual.  (Of course this will also convert IPonderIBM into I Ponder I B M, but you can't have everything you want & maybe it's a good idea.)

Anyway, that's perl 5.005 syntax.  Somebody else probably has an alternative expression for doing this... it's the beauty (or horror!) of REs.

(Caveat.  I confess that I don't know much about the various implementations of perl in the Windows world, and I know next to nothing about how REs vary from Java to VB & the like, but if one's using a perl-based program, 5.005 is a pretty old & widely used version & I think the above RE syntax would be supported. :eh: :shrug:  You're a brave man, Narayan, to embark on these waters! :P)

Want to try another?

narayan
Platinum Member
Platinum Member
Posts: 1430
Joined: 2002 Jun 04, 07:01

Post by narayan » 2006 Apr 15, 11:25

No that capital-separation script you posted earlier works, of course.

What I meant is the kind given below:

01-introduction (to be converted to 01-Introduction)
02introduction (to be converted to 01Introduction)

User avatar
JamieG
Member
Member
Posts: 47
Joined: 2004 Oct 03, 11:43
Location: Paris, France

Post by JamieG » 2006 Apr 15, 14:38

Are you looking for an RE that does that?  If so

        s/^(\d+\W*)(.)(.*)/$1\u$2$3/

will do the trick.  (Although looking closely at your example, if you want it always to come out as section "01", you'd need s/^\d+(\W*)(.)(.*)/01$1\u$2$3/.)

Best, Jamie :wink:

User avatar
FrizzleFry
Platinum Member
Platinum Member
Posts: 1142
Joined: 2005 Oct 16, 19:09

Post by FrizzleFry » 2006 Apr 15, 18:10

narayan, I forgot that \w matches alphanumeric rather than just alphas. This one should do the trick:

$file =~s/([A-Za-z].*)/\u\L$1/;

This defines a substring starting with the first letter and including the rest of the filename, caps the first letter (\u) and lowercases the rest (\L).

Update: I replaced the + (1 or more) with * (0 or more) to deal with filenames like "1 - a".
Last edited by FrizzleFry on 2006 Apr 15, 18:20, edited 2 times in total.

narayan
Platinum Member
Platinum Member
Posts: 1430
Joined: 2002 Jun 04, 07:01

Post by narayan » 2006 Apr 15, 18:10

Thanks!

I didn't find any other software that does renaming right in the context menu.

So this info too is worth putting in the manual (Including your scripts) :)

User avatar
FrizzleFry
Platinum Member
Platinum Member
Posts: 1142
Joined: 2005 Oct 16, 19:09

Post by FrizzleFry » 2006 Apr 15, 21:19

Demetris wrote:[auxRename] does not work with Unicode filenames, but, then, I don't know of any such tool that does. :(
MRename, http://fly.srk.fer.hr/~rajko/MRename/, claims to support Unicode filenames.  I do not deal with international characters much so I have not really tested this though.

narayan
Platinum Member
Platinum Member
Posts: 1430
Joined: 2002 Jun 04, 07:01

Post by narayan » 2006 Apr 16, 03:29

But if it can replace a single character at a time (as you pointed out earlier), not much use!

User avatar
FrizzleFry
Platinum Member
Platinum Member
Posts: 1142
Joined: 2005 Oct 16, 19:09

Post by FrizzleFry » 2006 Apr 16, 09:04

I guess, my previous statement about MRename is somewhat misleading. Its substitution command (search & replace) only works on single characters rather than strings; however, using its field definitions, it is possible to perform some complex rename operations.  Its support of Unicode characters might be useful to some and it does provide renaming options from the context menu.

narayan
Platinum Member
Platinum Member
Posts: 1430
Joined: 2002 Jun 04, 07:01

Post by narayan » 2006 Apr 16, 09:16

Sp let us compare awxrenamer and this one, then!

I will try out MRename; although I too have never needed Unicode in my file names.

narayan
Platinum Member
Platinum Member
Posts: 1430
Joined: 2002 Jun 04, 07:01

Post by narayan » 2006 Apr 18, 13:49

Tried out MRename 1.7. It has a RegExbased GUI; so it can be enjoyed best by those who know RegEx; but the default list is not bad either.

Like the awxrenamer, this too requires some additional options.

FrizzleFry/JamieG, could you please tell us how to-
1. Capitalize the first letter; and lowercase the rest

2. Separate words and convert to "Only first letter capital"
   e.g. Convert WorksForMe to Works for me.

3. Find a string and replace it with another string
   ((ask for both strings at runtime)

Of course, this is supposed to serve only as a quick-fire solution. Many many more things can be done with THE Rename.

***
For example, I found a none-too-good answer for problem#1 above, as follows:

Selection mask: ?1*2
(Save the first letter to Block-1; and the rest--including the file's extension-- to Block-2)

Rename mask: \U1\L2
(uppercase version of Block-1 and then lowercase version of Block-2)

Of course, this will not work at all if the file begins with a number.

Over to you, FrizzleFry and JamieG!

Post Reply