Important alert: (current site time 7/15/2013 8:59:14 PM EDT)
 

VB icon

case.pl

Email
Submitted on: 4/28/2002 1:16:15 AM
By: James Shepherd  
Level: Beginner
User Rating: Unrated
Compatibility: 5.0 (all versions)
Views: 8862
(About the author)
 
     I ran into a problem moving a company from NT servers to linux running samba. All of the files and users home directories where in varied case. While case had never been an issue before the administrators decided that they wanted it as easy as possible for their employees to remember usernames and to create the logon scripts, so i search for a while but could not find anything that would change all of the directory names at once. I am sure there is an easier way, but i grabbed a LLama book and wrote this in aboout an hour. The only thing it does is change the case of all files in a directory (including directory names) to either UPPERCASE or lowercase.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
=**************************************
= Name: case.pl
= Description:I ran into a problem moving a company from NT servers to linux running samba. All of the files and users home directories where in varied case. While case had never been an issue before the administrators decided that they wanted it as easy as possible for their employees to remember usernames and to create the logon scripts, so i search for a while but could not find anything that would change all of the directory names at once. I am sure there is an easier way, but i grabbed a LLama book and wrote this in aboout an hour. The only thing it does is change the case of all files in a directory (including directory names) to either UPPERCASE or lowercase.
= By: James Shepherd
=
= Inputs:The only way i could quickly figure this out is to have all filenames i wanted changed into a file, I used this.It will output all directories and filenames in the current directory ( along with their case ).Then read each line of that file and pass it through the case program.
ls > new
for i in new; do ./case.pl $i; done
=
= Returns:None
=
= Side Effects:It will change *all* files to whichever case you desire. If there are files or directories that you do not want changed, edit the "new" file before running the command.
=
=This code is copyrighted and has= limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=318&lngWId=6=for details.=**************************************

#!/usr/bin/perl
#version 1.0
#case.pl - change all files and folders in a directory to lowercase 
#	or UPPERCASE. In your directory type 
#
#USAGE: ls > new; for i in new;do ./case.pl $i;done
# for upper case move # up one line:
# by James Shepherd - james@netjames.com - www.netjames.com
while (<>) {
chomp;
$n = $_;
s/$_/\L$_/gi;# Lowercase line
#s/$_/\U$_/gi;#UPPERCASE LINE
rename $n, $_;
print "Success renaming $n to $_ !\n";
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

4/29/2002 4:32:15 PMT. E. Geek

I like the regular expressions ;-) However, they are not entirely needed :-p. There are a number of case modifying functions which have been optimized/inlined in perl as part of the standard package. Foremost, you could have interpolated a \U and \E or \L and \E in a string to uppercase a variable between the two escape sequences it. Or, you can even use the uc and lc functions.
(If this comment was disrespectful, please report it.)

 
4/29/2002 11:22:22 PMJames Shepherd

Thanks T. E.
I would like to know a little more and am now finding a few easier ways of doing the same thing. Thamks for the input.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.