Filename case changing

A swapping-ground for Regular Expression syntax

Filename case changing

Postby MagratG » Sat Dec 01, 2018 3:34 pm

I've tried to search for answers to this question but 'case' and 'change' are too common!
I'm trying to tidy up a large directory, full of file names all in lower case. Using 'Case' 'Title' works well and I can exclude words like 'of'', 'the', 'to' by putting them in the 'Exclude' list. However, I don't want to change the word if it is at the beginning of the filename.
Is this possible?
I think I could do it by renaming using the above method, than resetting and doing another rename but selecting the 'Sentence' option for 'Case'.
MagratG
 
Posts: 2
Joined: Mon Mar 16, 2009 5:30 pm

Re: Filename case changing

Postby Jack2 » Sat Dec 01, 2018 4:48 pm

There was a similar question here, except the poster wanted to change the case of the 20th character
viewtopic.php?f=11&t=3884&p=10045&hilit=20th#p10045

It would be easy enough to change the script to change (back) the case of the first character, but note that you need a commercial licence to save the changes made in javascript


I had to do a similar thing recently. I have a workaround which could be adapted, but it is kinda painful. Let's see if someone comes up with an easy way first (I imagine it is easy with Regular Expressions).


than resetting and doing another rename but selecting the 'Sentence' option for 'Case'.

No, using 'sentence' would reset all your Title capitals back to lowercase (except the first one, of course).


and I can exclude words like 'of'', 'the', 'to' by putting them in the 'Exclude' list

you know to put spaces before and after each word in the Exclude list, right? : of : the : to : Otherwise, "to" will be read as "*to*" and tokyo will not be changed to Tokyo.

Also, be careful using Titles case if you have Roman numerals (Iii) or things which need to be all capitalised (Ibm)


However, I don't want to change the word if it is at the beginning of the filename.


To be clear - you are saying that the first character is always lower case and you want to keep it that way, right? You want to change "one two the three" to "one Two the Three" ?

or are you saying that you want to exclude a word from the exclusions list if it appears at the start of the line. Such that "of four five the six" becomes "Of Four Five the Six"
Jack2
 
Posts: 30
Joined: Wed Nov 14, 2018 4:32 pm

Re: Filename case changing

Postby Jack2 » Tue Dec 04, 2018 11:12 am

Not sure if the OP is coming back, so I'll just dump my workaround here, so I can forget about it.

Also, I'm not sure whether his requirement is to force the first character to uppercase or to lowercase.

Scope:
I'm assuming that the OP has already used his mentioned method (Title Case with Exclusions) to change
of mice and men.txt
into
of Mice and Men.txt

and now he wants to change that to
Of Mice and Men.txt

---------

This method makes a text file of all the filenames, then uses Excel to force the first character into uppercase then generates a script which can be used to rename the original files with uppercase first letters.


1) First, make a text file containing all your filenames:
either in Command line interface. (search windows for "command", hit enter, type the drive letter and : (e.g. d:), hit enter; type cd and type/paste the path statement of your folder (e.g. cd D:\DOWNLOADS\0 test\), hit enter; paste in dir /b >filelist.txt , hit enter

This will generate a textfile called filelist.txt (in the same directory as the files you want changed) containing a list of all the filenames.

As an alternative to using command line to get the filelist, you could use apps like:
https://www.karenware.com/powertools/karens-directory-printer
.
or
.
https://download.cnet.com/PrintFolders/3000-2248_4-10067127.html


2) Open your filelist.txt, Select All, then Copy. Then paste it into Column A of Excel (or Libreoffice Calc, etc.)


3) paste this into cell B1:
=(UPPER((LEFT(A1,1))))&(RIGHT(A1,(LEN(A1)-1)))

(btw, if you are trying to force the first letter into Lowercase, then change "UPPER" to "LOWER" in the formula)

Fill/Paste B1 all the way down the page in Column B

Column B is a list of the filenames with the first letter capitalised.

4a) if all your files are in the same folder, paste this into cell C1:
="ren "&CHAR(34)&A1&CHAR(34)&" "&CHAR(34)&B1&CHAR(34)
fill/paste down the rest of column C
copy column c
go back to your command line window (which is still at the correct directory)
paste column C into the command line window (Cntl+v)

that's it!

4b) if your files are all in different subdirectories or you don't want to use the command line, paste this into cell D1:
=A1&"|"&B1
fill/paste D1 down the page in column D
copy/paste Column D into a new textfile and save it as, say, "rename-pairs.txt"
return to BRU
In the treeview (left) window, navigate to your folder containing your files (in the usual way)
Check the "subfolders" box in the section 'Filters(12)'
go to BRU menu Actions>Import Rename-Pairs
navigate to where you saved 'rename-pairs.txt' and click to load it
Highlight all the files in the main window of BRU. The ones that need to be changed will appear in green,as ususal.
Click "Rename", as usual.

that's it!

.

btw,
The formula in B1 just strips-off the first character in the line, changes it to a capital then reattaches it. Everything else (e.g. putting capitals on the other words, handling exceptions like 'to, the, of', etc), you have to (first) do yourself using BRU's standard tools.
Jack2
 
Posts: 30
Joined: Wed Nov 14, 2018 4:32 pm

Re: Filename case changing

Postby thewordguy » Fri Jun 14, 2019 1:28 am

I was having the same problem because I wanted correct title-case capitalization where the first letter of each word was capitalized but skipping joining words that were not at the start or beginning of the sentence (This is an Example of What I Needed to Do) so I came here to post my solution like a good netizen...

It's actually really easy, you just have to add spaces before and after each excluded word so that they only change if they appear in the middle of the sentence.

This is my current exclusion list in quotes (remove the quotes obviously) " to : of : by : in : for : is : on : vs : at : the : and : with : but : or : a : an "

of mice and men.txt
into
Of Mice and Men.txt
thewordguy
 
Posts: 1
Joined: Fri Jun 14, 2019 1:18 am


Return to Regular Expressions