/ Published in: Perl
Renames files in a directory. If no directory is specified, the current directory is used.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#! /usr/bin/perl ## ## Renames files in a directory. If no directory is ## specified, the current directory is used. ## use strict; use warnings; use File::Copy; use Getopt::Long; my $directory = ""; my $from = ""; my $to = ""; my $getOptionsResult=GetOptions( "--directory=s" => \$directory, "--from=s" => \$from, "--to=s" => \$to, ); &displayUsageAndDie if $to eq ""; &displayUsageAndDie if $from eq ""; $directory = "." if $directory eq ""; { &renameFiles($_,$to) if m/$from/; } sub renameFiles() { my $f = $_; (my $t = $f) =~ s/$from/$to/g; } sub displayUsageAndDie() { print " Renames files in a directory. If no directory is specified, the current directory is used. usage: rename --from from --to to [--directory directory] "; }