Capitalize first character in file names, w/ regexp replace?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Post Reply
aliteralmind
Posts: 255
Joined: 02 Dec 2014 16:49

Capitalize first character in file names, w/ regexp replace?

Post by aliteralmind » 05 Mar 2015 17:54

Code: Select all

^([a-z]) > $1
This does nothing; it changes the first character to itself.

With regexes in TextPad, I can capitalize the next character with:

Code: Select all

^([a-z]) > \u$1
Is there any way to do this with XY's RegExp Rename? My goal is to capitalize the first character in each selected filename.
Windows 8.1, 64-bit

SammaySarkar
Posts: 4205
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612 / Dhaka
Contact:

Re: Capitalize first character in file names, w/ regexp repl

Post by SammaySarkar » 05 Mar 2015 18:01

out-of-script quickie: commands #138 or #126 (File > rename Special > A* A*.ext and Aaa Aaa.ext)
ed. "first char only", so probably no help.

admin
Site Admin
Posts: 47703
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Capitalize first character in file names, w/ regexp repl

Post by admin » 05 Mar 2015 20:34

If scripting is an option, either of these?

Code: Select all

text recase("the caMel can't.", "title"); //The Camel Can't.
text recase("the caMel can't.", "sentence"); //The camel can't.

kunkel321
Posts: 567
Joined: 10 Jun 2012 03:45
Location: Near Seattle

Re: Capitalize first character in file names, w/ regexp repl

Post by kunkel321 » 05 Mar 2015 20:35

Not an answer to your question, but the free version of ReNamer can do it...
http://www.den4b.com/?x=products&product=renamer

Edit: You beat me to it Don. :)
ste(phen|ve) kunkel

admin
Site Admin
Posts: 47703
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Capitalize first character in file names, w/ regexp repl

Post by admin » 05 Mar 2015 20:39

kunkel321 wrote:Not an answer to your question, but the free version of ReNamer can do it...
http://www.den4b.com/?x=products&product=renamer

Edit: You beat me to it Don. :)
Yep, and I wonder why you post a link to some external app for such a trivial task. :? Hey, this is XY, man!

Edit: Of course, being RegEx-dumb I have no idea how it could be done. I just *think* it should be easy. :whistle:

Anyway, I just added a switch /u to just uppercase the first letter. This functionality was missing an easy way AFAIK.

aliteralmind
Posts: 255
Joined: 02 Dec 2014 16:49

Re: Capitalize first character in file names, w/ regexp repl

Post by aliteralmind » 05 Mar 2015 20:59

I'm trying to rename files like "twoThings.java" to "TwoThings.java", so passing the entire string won't work. I only want to upper (only want to *change*) the first character.

Maybe if I parse the string and then pass the first character to recase.

I'll give that a try.
Windows 8.1, 64-bit

aliteralmind
Posts: 255
Joined: 02 Dec 2014 16:49

Re: Capitalize first character in file names, w/ regexp repl

Post by aliteralmind » 05 Mar 2015 21:39

admin wrote:Anyway, I just added a switch /u to just uppercase the first letter. This functionality was missing an easy way AFAIK.
SWEET!!! :appl: :biggrin: :shock: :ugeek: :lol: These are all the related switches in TextPad (and the Boost regex engine, which it uses):

Code: Select all

\l - Causes the next character from the format expression to be output in lower case. 
\u - Causes the next character from the format expression to be output in upper case. 
\L - Causes all subsequent characters to be output in lower case, until a \E is found. 
\U - Causes all subsequent characters to be output in upper case, until a \E is found. 
As documented under "escape sequences" at the bottom of this page.
Windows 8.1, 64-bit

TheQwerty
Posts: 4353
Joined: 03 Aug 2007 22:30

Re: Capitalize first character in file names, w/ regexp repl

Post by TheQwerty » 05 Mar 2015 21:54

Well until the next beta... :whistle:

Code: Select all

"Capitalize First Letter"
	// Unique prefix so Search & Replace is anchored.
	$uniq = <date yyyymmddhhnnss> . '-' . rand(0,100) . '__';
	// Search list ($uniq . [a-z])
	$s = '';
	// Replacement list ([A-Z])
	$r = '';
	// Build the strings for each letter.
	$i = 0;
	while ($i < 26) {
		$s = $s . $uniq . chr(97+$i) . ($i<25 ? '|' : '');
		$r = $r . chr(65+$i) . ($i<25 ? '|' : '');
		$i++;
	}

	// Prepend items starting with lowercase characters with the unique prefix.
	Rename 'r', '^([a-z]) > ' . $uniq . '$1\', 'p';
	// Search and replace rename.
	Rename 's', "$s>>$r\", 'p';
That said I too am saddened that VBScript/XY dooes not support the case conversion syntax.

admin
Site Admin
Posts: 47703
Joined: 22 May 2004 16:48
Location: Cologne, Win 8.1, Win 10
Contact:

Re: Capitalize first character in file names, w/ regexp repl

Post by admin » 08 Mar 2015 12:06

aliteralmind wrote:
admin wrote:Anyway, I just added a switch /u to just uppercase the first letter. This functionality was missing an easy way AFAIK.
SWEET!!! :appl: :biggrin: :shock: :ugeek: :lol: These are all the related switches in TextPad (and the Boost regex engine, which it uses):

Code: Select all

\l - Causes the next character from the format expression to be output in lower case. 
\u - Causes the next character from the format expression to be output in upper case. 
\L - Causes all subsequent characters to be output in lower case, until a \E is found. 
\U - Causes all subsequent characters to be output in upper case, until a \E is found. 
As documented under "escape sequences" at the bottom of this page.
I think the new /u switch will meet most real world desires (that are not already met by other XY functions).

Post Reply