#!/usr/bin/perl -w
use strict;
use File::Copy;
use File::Spec;
my($chptr, $base_path, $new, $dir);
$dir = "Full Metal Alchemist"; #Some dir
opendir(FMA, $dir) or die "Can't open FMA dir";
while($chptr = readdir FMA){
$base_path = File::Spec->rel2abs($dir).'/'; #find absolute path of $fir
if($chptr =~ m(Chapter\w*\d*)){ #some regex to avoid the .. and . dirs
$new = join(" 0", split(/\W/, $chptr)); #modify said sub directory
rename "$base_path$chptr", "$base_path$new" ? print "Renames $base_path$chptr to
$base_path$new\n" : die "rename failed $!";
}
}
closedir FMA;
最初,我的脚本只使用相对路径来执行move操作,但由于某些原因,这会使子目录不受影响。我的下一步是去绝对路径,但无济于事。我只是在学习Perl,所以我觉得我犯了一个简单的错误。我哪里错了? TIA在Perl中重命名子目录
你想避免什么问题? – aleroot
目前,我从重命名声明中得到误判。我想重命名子目录。我唯一避免的是试图重命名核心。和..链接 –