--PNTmBPCT7hxwcZjr Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Aug 07, 2002 at 10:49:32PM -0700, technomage wrote: > ok, > I've read and I've read, but can't seem to come up with a solution that isn't > overly complex. > I want t take spaces in filenames and rename them with underscores "_" and > would like to do so a directory at a time if need be. > > any help would be appreciated Save the attached perl script, make it executable, and issue the command ./rename 's/ /_/g' file(s) e.g. ./rename 's/ /_/g' *.mp3 The script applies the operation in the first argument to the file names and renames them if a different name is produced. This is what I use any time I need to rename multiple files in a consistent way. You can use any valid perl expression for the first argument, so it's pretty powerful. For example, you can do things like: convert filenames to lowercase ./rename 'tr/A-Z/a-z/' file(s) capitalize every word in the file names specified ./rename 's/\b(\w)(\w*)/uc($1).lc($2)/eg' file(s) -Mike --PNTmBPCT7hxwcZjr Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=rename #!/usr/bin/perl $op = shift; for (@ARGV) { $was = $_; eval $op; die $@ if $@; rename($was,$_) unless $was eq $_; } --PNTmBPCT7hxwcZjr--