tired of getting whitespaces in filenames (mp3, pr0n, bosses' latest decree)?
( @ARGV ) || die "Usage : $0 /some/directory /another/directory\n"; foreach $directory ( @ARGV ) { if ( -d $directory ) { chdir("$directory"); convert_dir(); chdir("-"); } } sub convert_dir { chomp( my $dir = `pwd`); opendir(DIR,"$dir"); while ( my $file = readdir DIR ) { my $oldname = "$file"; $file =~ s/\s+/_/g; # print "Renaming $oldname to $file\n"; rename("$oldname","$file"); } close(DIR); return 1; } ___ | | | x | <---bang head here if this |___| frustrates you
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: convert whitespaces to underscores
by Juerd (Abbot) on May 26, 2002 at 00:03 UTC | |
Re: convert whitespaces to underscores
by mattriff (Chaplain) on May 26, 2002 at 03:09 UTC | |
by merlyn (Sage) on May 26, 2002 at 22:15 UTC | |
(crazyinsomniac) Re: convert whitespaces to underscores
by crazyinsomniac (Prior) on May 26, 2002 at 22:29 UTC | |
by Juerd (Abbot) on May 26, 2002 at 23:23 UTC | |
Re: convert whitespaces to underscores
by Galen (Beadle) on Jun 24, 2002 at 19:32 UTC |
Back to
Cool Uses for Perl