📜  将文件移动到新目录 - Perl 代码示例

📅  最后修改于: 2022-03-11 14:48:10.900000             🧑  作者: Mango

代码示例1
foreach my $file (@files) 
{
    my $old = "$srcdir/$file";
    my $new = "$dest/$file";
    my $subdir = $file;
    while (length($subdir)>0)
    {
        if (-d "$dest/$subdir")
        {
            $new = "$dest/$subdir/$file";
            last;
        }
        chop($subdir);
    }

    rename($old, $new) or die "Move $old -> $dest failed: $!";
}