develooper Front page | perl.golf | Postings from March 2006

file renamer (i'm a newbie)

Thread Next
From:
Eric Waguespack
Date:
March 24, 2006 15:33
Subject:
file renamer (i'm a newbie)
Message ID:
1c246150603241533j7edbb078tcb365eb804960cbb@mail.gmail.com
Currently the file below renames files by changing spaces to underscores.
usage:
find | ./file_name_fixer.pl

how could it be shortened up?

I would eventually like to modify it so that it will will modify names
so that they only contain 'a-z0-9._'

thanks.



#!/usr/bin/perl

while (<>)
{
 chomp;
 unless (-e $_)
 {
 print "$_ <=== does not exist\n";
 next;
 }
 $oldname = $_;
 s/ /_/;
 if ($oldname eq $_)
 {
 next;
 }
 if (-e $_)
 {
 print "$_ <=== already exists\n";
 next;
 }
 print "renaming $oldname ===> $_\n";
 rename $oldname, $_;

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About