Operating System - HP-UX
1833569 Members
4436 Online
110061 Solutions
New Discussion

Share with you: a simple script

 
SOLVED
Go to solution
discoverer
Frequent Advisor

Share with you: a simple script

Name: up2low
Function: Move all the filenames/dirnames under the
input directories, from
upper case to lower case
Usage: itmv
E.g. up2low DIR_NAME1 DIR_NAME2

Content:
#!/sbin/sh
for i in `find $* \( -type f -o -type d \) | sort -r`
do
mv ${i} "`dirname ${i}`/""`basename ${i}|tr '[A-Z]' '[a-z]'`"
done


Hope it can help you!

/Listener
Listen, then discover, then succeed!
3 REPLIES 3
Tim D Fulford
Honored Contributor

Re: Share with you: a simple script

Thanks,

I'll put that one in my blue book!

Tim
-
Wodisch
Honored Contributor
Solution

Re: Share with you: a simple script

Hello "discoverer",

I would recommend to first test for the existence of
the "new" (uppercase) file in the target directory, as
you may create the same upper case name from more
than one mixed case names, e.g.:

source-dir:
aFile Afile AFile aFiLe

target-dir:
AFILE

You see the danger?

Just my ?0.02,
Wodisch
PS: Did we not have a thread about that?
discoverer
Frequent Advisor

Re: Share with you: a simple script

Hi Wodisch,

You are really a sharp 'wizard'!

So, there should be an additional check on the target filename before 'mv', then if confilict, we should report these files, then abort or 'mv' it to a new name, depending on our conditions.

For my users' requirements, there is no such a risk.

Thanks for your attention!

/Listener
Listen, then discover, then succeed!