Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change file name to upper case

Status
Not open for further replies.

knsnln

Technical User
Oct 2, 2002
7
0
0
US
I can change all file names to upper case except the file "_ccmwaid.inf". How could it happen? Is ther any problem with pattern matching? " m/([a-zA-Z0-9._~\s]+)[-'#.!?]?\s*$/x;"

Thanks
 
Yes there is a problem - underscore doesn't have an uppercase equivalent! You will have to do some string manipulation first to remove this character, change the rest to uppercase, then put the _ back again. Or just substitute the alphabetical characters, ignoring numerics and punctuation.
Just as a point of interest, why do you want to do this? I normally have the opposite problem - where email addresses and filenames need to be in lowercase!
 
The question why is good.

If you're uppercasing all file names, what OS are you running this on. In a case sensitive OS, you're setting yourself up for a world of hurt.

;P
 
Why don't you just use
Code:
uc("_ccmwaid.inf");
 
I don't need to change the "_" (leave as it is), but I do want to change the rest of them to upper case when reading from a file. I am using Win2000. It seems that a file name or directory start with a "_" did not get pick up on the pattern matching I mentioned before. I can do: uc("_ccmwaid.inf"), but I still need to a way to be working on general case, not just for particular.
 
I don't think it's the regex. I tested it and it works. How are you upcasing the filenames if you are not using uc()?

jaa
 
Would you let me know how you tested. I create a file name that starts with "_" (undersore) and tried to change the file name to either upper or lower using "uc" or "lc", but it did not work. Any advice?
 
I only tested matching the filename (which is where you indicated the problem lies). I didn't actually change any filenames.
Code:
#!/usr/bin/perl -w

use strict;

while (<DATA>) {

    chomp;
    if ( m/([a-zA-Z0-9._~\s]+)[-'#.!?]?\s*$/x ) {

        printf &quot;%-14s => %s\n&quot;, $1, uc($1);
    }
}

__DATA__
blarf.inf
_ccmwaid.inf
foo_bar.inf
Zaza.inf!
Which gives the following output:
Code:
blarf.inf      => BLARF.INF
_ccmwaid.inf   => _CCMWAID.INF
foo_bar.inf    => FOO_BAR.INF
Zaza.inf       => ZAZA.INF
jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top