The Haiku/BeOS Tip Server
Tips and tricks for Haiku/BeOS users

Batch-changing filename cases

Contributed by: Scot Hacker
This tip is valid for: Both BeOS and Haiku

On occassion, you may find it useful to be able to change all the filenames in a directory from UPPERCASE to lowercase, or vice versa. This will be particularly true if you’re copying over file from a Windows 95/98 partition, since Windows is so inconsistent with its case handling. Here’s a shell script you can use to automate the process. Type or copy the following lines into Terminal, one at a time:

for i in * ; do
  j=`echo $i|tr 'A-Z' 'a-z'`
  mv "$i" "$j"
done

To change from lowercase to uppercase, reverse the order of ‘A-Z’ ‘a-z’. The script requires that the tr utility be in your /bin/ directory, which it should be by default. If you think you’ll use this often, make a script out of it for later use. Paste the above into a text file, but add the line

to the top, as the first line. Save it with the name “lowercase.” Then make it executable by typing chmod 755 lowercase into Terminal. Edit the file again to do the uppercasing trick, and save the new file as “uppercase.” Run chmod on that too. Move both of these files to your /boot/home/config/bin/ directory, and they’ll always be available to you from the command line.

If you’d rather download these scripts, ready to run, you can get them here.

Posted in Scripting


(comments are closed).