The following Perl script may work for you:
#!/usr/bin/env perl
use strict;
use warnings;
use File::Basename;
use File::Find;
use File::Spec;
sub rename {
my ($dir_name) = ( File::Spec->splitdir($File::Find::dir) )[-1];
my $file_name = basename $_;
if ( -f $_ ) {
$file_name = "$dir_name-$file_name";
rename $_, File::Spec->catdir( $File::Find::dir, $file_name );
}
}
find { 'wanted' => &rename, 'no_chdir' => 1 }, 'C:/test/foo';
References:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…