Recursively stripping spaces/uppercase from filenames
Posted in Linux at 05:12PM on 03/25/2009

Upper-case letters/spaces are annoying to deal with in Linux.  We're caching some filenames to avoid hammering servers for software packages.  It's handy to remove spaces/uppercase letters to control potential errors/configurations/links.  There's all sorts of applications from smb servers, mail servers, scripts, etc.

There's a small problem, it's easy to do that on a single directory or run loops to recurse throughdirectories but it's hardly efficient and it's sloppy code.

Run against:

win/amr/2008 Disc Installer.iso

Will output:

./win/amr/2008
Disc
installer.iso

Another option is to do a simple find/for loop but that will break when you do spaces unless you have additional code to clean that up, again, sloppy.

A solution:

 As commented, this will correctly put the entire filename in $file allowing proper execution against it.

Comments
(will not be displayed)
© 2008 Radio Web Services