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!

Converting directory names to upper case

Status
Not open for further replies.

knsnln

Technical User
Oct 2, 2002
7
0
0
US
My situation is that I have a very big file with mixed case directories and subdirectories. Under each directories, there are multi files. My goal is to replace all lower case characters in the directories to upper case and all upper case characters in each file names to lower, or vice versa. So far I can only do this with one dir but the format seem to be not right. I was wondering if there is any one has any idea of how to do that, or perhaps has sample codes.

Thanks
 
Disclaimer: Try this on a test directory first!!!

basically
my $os=uc($^O );
my %copyhash=('UNIX'=>'cp','MS-WIN'=>'copy');
#the idea is to use copy for windows and cp for Unix.
# I do not recall if it is MS-WIN or MSWIN32 or whatever,
# so it is best to check $^O on your system and code this in
#hash
opendir (DIR, "$somedirectory") or die "cannot open $somedirectory\n" ;
foreach my $file(readdir DIR){
my $file1=uc($file);
system ("$copy $file $file1");#copyfile to uppercaSE
unlink $file; #get rid of old file
}
###ps yOU CAN DO THIS IN ONE STEP BY USING MV AND RENAME ON COPYHASH

iS TAHT WHAT YOU WERE LOOKING FOR?
 
a shell (slow) version.....

FOR DIRS:

make a vertically reversed list of your dirs
i mean:
aaaa
aaaa/aaaa
aaaa/bbbb
aaaa/cccc
aaaa/cccc/aaaa
becomes:
aaaa/cccc/aaaa
aaaa/cccc
aaaa/bbbb
aaaa/aaaa
aaaa
...
!!! sort -r is not adeguate !!!

if you have no reverse tool
find . -type d > aaa
edit aaa
vi aaa
issue the command to reverse all lines top to bottom
:g/.*/m$\n
save the file
:x\n

NOTA: interpret ' as backquote

for dir in 'cat aaa'
do
tokeep='dirname $dir'
toupper='basename $dir | tr "[a-z]" "[A-Z]"'
mv $dir $tokeep/$toupper
done

this will mv:

aaaa/cccc/aaaa to aaaa/cccc/AAAA
aaaa/cccc to aaaa/CCCC
aaaa/bbbb to aaaa/BBBB
aaaa/aaaa to aaaa/AAAA
aaaa to AAAA

FOR FILES: replace d to f in the find command. vox clamantis in deserto.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top