#!/usr/bin/perl
use strict;
use warnings;
use File::Copy;
use File::chdir; # allows cd-ing by use of $CWD, much easier but needs CPAN module
die "Usage: $0 dir prefix" unless (@ARGV >= 2);
my ($dir, $pre) = @ARGV;
opendir(my $dir_handle, $dir) or die "Cannot open directory $dir";
my @files = readdir($dir_handle);
close($dir_handle);
$CWD = $dir; # cd to the directory, needs File::chdir
foreach my $file (@files) {
next if ($file =~ /^\.+$/); # avoid folders . and ..
next if ($0 =~ /$file/); # avoid moving this script if it is in the directory
move($file, $pre . $file) or warn "Cannot rename file $file: $!";
}