[lug] Fixing filename characters...

Tkil tkil at scrye.com
Wed Jan 19 21:36:41 MST 2000


i tend to use something like this (broken onto separate lines for
readability, i tend to type it all in on one line in emacs
shell-mode).  it has the advantages of:  (1) not caring how many files
there are, and (2) only ever spawning one process (although the
xargs/awk approach can really reduce that as well, just watch out for
find's "-exec" flag!)

perl also has standard modules to help with things like recursive
directory scanning (perldoc File::Find) and rename'ing across
filesystems (perldoc File::Copy).

t.

perl -we 'foreach $dir (@ARGV) { \
  opendir D, $dir or die "opendir $dir: $!"; \
  while (defined($orig = readdir D)) { \
    $new = $orig; \
    $new =~ s/ /_/g; \
    rename $orig, $new or warn "rename $orig, $new: $!";
  } \
  closedir D or warn "closedir $dir: $!"; \
}' dir1 dir2 dir3

-- 
Tkil * <URL: http://slinky.scrye.com/~tkil> * hopelessly hopeless romantic.
  "So amplify this little one 	|   She hears as much as she can see
   She's a volume freak       	|   And what she sees, she can't believe."
        -- Catherine Wheel, _Happy Days_, "Judy Staring At The Sun"




More information about the LUG mailing list