LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-24-2009, 10:25 AM   #1
rootlinuxusr
LQ Newbie
 
Registered: Mar 2009
Distribution: X/K/Ubuntu 8.04
Posts: 2

Rep: Reputation: 0
CamelCase/CapitalCase, etc


I'm trying to create a process that renames all my filenames to Camel/Capital Case. The closest I have to getting there is this:

perl -i.bak -ple 's/\b([a-z])/\u$1/g;' *.txt # or similar .extension.

Which seems to create a backup file(which I'll remove when it's verified this does what I want); but instead of renaming the filename, it renames the text inside of the file. Is there an easier way to do this? The theory is that I have several office documents in various formats, as I'm a bit anal-retentive, and would like them to look like this:

New Document.odt
Roffle.ogg
Etc.Etc

Is this possible with perl, or do I need to change to another language/combination of them?

Also, is there anyway to make this recursive, such that /foo/foo/documents has all files renamed, as does /foo/foo/documents/foo?

Last edited by rootlinuxusr; 03-24-2009 at 10:42 AM. Reason: recursive.
 
Old 03-24-2009, 10:43 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
The only way this will work is to have an inclusivre, definitive rule that works on ALL filenames you intend to change. You have to be able to identify words - are they all delimited by spaces or underline characters, for example. With no delimiters in a filename you assume the filename is a single word.

What rule do you have?

BTW using spaces and shell metacharacters in filenames will cause you heartburn later on.
Guaranteed.
 
Old 03-24-2009, 10:46 AM   #3
rootlinuxusr
LQ Newbie
 
Registered: Mar 2009
Distribution: X/K/Ubuntu 8.04
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by jim mcnamara View Post
The only way this will work is to have an inclusivre, definitive rule that works on ALL filenames you intend to change. You have to be able to identify words - are they all delimited by spaces or underline characters, for example. With no delimiters in a filename you assume the filename is a single word.

What rule do you have?

BTW using spaces and shell metacharacters in filenames will cause you heartburn later on.
Guaranteed.
Currently they look like this:
file name.ogg
foo foo.txt
dog cat.odt

I assume that would be with spaces instead of underline? I have very, very little programming experience, but would love to learn.
 
Old 03-24-2009, 11:21 AM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
What is "Camel/Capital Case" ? I am not a native English speaker.
 
Old 03-24-2009, 11:50 AM   #5
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
Camel case is when you use capital letters for sub-words, e.g. someCamelCasedWord. So named because the letters are like the humps on a camel. Capital case (I assume) is the same, but with a capital letter at the beginning, e.g. SomeCapitalCasedWord. Camel case is the norm for variables in newer programming languages nowadays since longer variable names are expected (except in Lisp languages which prefer to use dashes to separate words). You still see underscore delimited words, but typically in older languages like C.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:59 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration