Change first letter in foldername (starting with 6 figures)

Javascript renaming examples. Javascript renaming is supported in version 3 or newer.

Change first letter in foldername (starting with 6 figures)

Postby Hasse » Sat Jul 16, 2016 5:27 pm

I have a number of folder names with the following pattern:

date_foldername (where foldername normally has only one word, but sometimes has more than one word, separated by spaces).

For example:
150830_foldername01
151117_foldername02
160115_foldername03 nextword
160509_foldername04 nextword nextword
160830_foldername05 nextword nextword nextword nextword

I want to convert just the first letter, in the foldername, to uppercase.
The rest of the foldername should be unchanged.

Like this:
150830_Foldername01
151117_Foldername02
160115_Foldername03 nextword
160509_Foldername04 nextword nextword
160830_Foldername05 nextword nextword nextword nextword


To catch the first "date-part" I thought of using
\d{6}_
as it is allways 6 figures, followed by an underscore.

Any idea how to solve the rest?
Hasse
 
Posts: 10
Joined: Sat Jul 16, 2016 4:52 pm

Re: Change first letter in foldername (starting with 6 figures)

Postby Admin » Wed Jul 20, 2016 3:05 pm

I think you need Javascript to do this which requires a BRU commercial license. If you have a commercial license I can post the script you need. thanks
Admin
Site Admin
 
Posts: 1484
Joined: Tue Mar 08, 2005 8:39 pm

Re: Change first letter in foldername (starting with 6 figures)

Postby therube » Wed Jul 20, 2016 3:51 pm

Actually it appears that all that is needed is 4:Case.

4:Case -> Sentence

Now note that if 'nextword nextword nextword nextword' include any CAPS, then they will be changed to lowercase.


(I sure didn't expect that. And all this time, I've been trying to figure out if PCRE had or if the version here included some sort of UPPER [or lower] function [\U], or similar.)
therube
 
Posts: 347
Joined: Mon Jan 18, 2016 6:23 pm

Re: Change first letter in foldername (starting with 6 figures)

Postby Hasse » Thu Jul 21, 2016 12:27 pm

Thank you for your reply!

I have ordered a commercial licence today and will appreciate if you will post the Javascript code here.
Hasse
 
Posts: 10
Joined: Sat Jul 16, 2016 4:52 pm

Re: Change first letter in foldername (starting with 6 figures)

Postby Admin » Thu Jul 21, 2016 5:04 pm

Thank you for purchasing BRU. Please try this Javascript code. thanks!

Code: Select all
// replace char in in position 8 with uppercase
var i = 7;

String.prototype.replaceAt=function(index, character) {
    return this.substr(0, index) + character + this.substr(index+character.length);
}

var str = name;
var ch = str.substr(i,1);
ch = ch.toUpperCase();
str = str.replaceAt(i, ch);

newName = str;
Admin
Site Admin
 
Posts: 1484
Joined: Tue Mar 08, 2005 8:39 pm

Re: Change first letter in foldername (starting with 6 figures)

Postby therube » Thu Jul 21, 2016 5:29 pm

Should that work - even in the free version, using the 'Test' function in 'JavaScript Renaming'?
That is if I enter:
Code: Select all
From: abcdefghijk


Should clicking Test cause To to change to:
Code: Select all
  To: abcdefGhijk


Cause if so, I'm not seeing it on my end?
therube
 
Posts: 347
Joined: Mon Jan 18, 2016 6:23 pm

Re: Change first letter in foldername (starting with 6 figures)

Postby Hasse » Thu Jul 21, 2016 5:43 pm

Thank you Admin!

It works perfectly!
Hasse
 
Posts: 10
Joined: Sat Jul 16, 2016 4:52 pm

Re: Change first letter in foldername (starting with 6 figures)

Postby Admin » Fri Jul 22, 2016 2:01 pm

Hi, yes, the preview should work with the free version too, but it will not allow to actually rename the files.
Admin
Site Admin
 
Posts: 1484
Joined: Tue Mar 08, 2005 8:39 pm

Re: Change first letter in foldername (starting with 6 figures)

Postby therube » Fri Jul 22, 2016 3:53 pm

Cause if so, I'm not seeing it on my end?


I could have sworn when I tested yesterday, I was not seeing any change.
But looking again now, it sure did.
Guess I just missed the change yesterday?


And then I was in the process of writing:
Ah, no I did not miss it.
It was actually not working.

But even that is not holding water - right now.

So, at this point, I'll say it is working.
(But... I think there is something weird going on? I'll keep looking...)
[Or I'm just flat out wrong about that. Has happened before :-).]
therube
 
Posts: 347
Joined: Mon Jan 18, 2016 6:23 pm

Re: Change first letter in foldername (starting with 6 figures)

Postby Admin » Mon Jul 25, 2016 5:05 am

No worries! :)
BTW thank you very much for helping many BRU users!
Admin
Site Admin
 
Posts: 1484
Joined: Tue Mar 08, 2005 8:39 pm


Return to Javascript Renaming