Rename a file with perl
Posted
by perlnoob
on Stack Overflow
See other posts from Stack Overflow
or by perlnoob
Published on 2010-04-05T19:07:02Z
Indexed on
2010/04/05
19:23 UTC
Read the original article
Hit count: 385
I have a file in a different folder I want to rename in perl, I was looking at a solution earlier that showed something like this:
for (<backup.rar>) {
my $file = $_;
my $new = $_ 'backup'. @test .'.rar';
rename $file, $new or die "Error, can not rename $file as $new: $!";
}
however backup.rar is in a different folder, I did try putting "C:\backup\backup.rar" in the <> above, however I got the same error.
C:\Program Files\WinRAR>perl backup.pl String found where operator expected at backup.pl line 35, near "$_ 'backup'" (Missing operator before 'backup'?) syntax error at backup.pl line 35, near "$_ 'backup'" Execution of backup.pl aborted due to compilation errors.
I was using
# Get time
my @test = POSIX::strftime("%m-%d-%Y--%H-%M-%S\n", localtime);
print @test;
To get the current time, however I couldn't seem to get it to rename correctly.
What can I do to fix this? Please note I am doing this on a windows box.
© Stack Overflow or respective owner