Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
... my $dir_path = "/my_dir"; my @dir = <$dir_path/*.*>; if (@dir) { foreach (@dir) { next if -d; my $temp_f_name = basename( $_ ); # get just the file extension (my $file_extention = $temp_f_name)=~s/^([^_]+_)(.*)(\.\w{3,4})\z$ +/$3/eg; my $renamed_file ="oldsince_"."$file_extention"; rename($temp_f_name, $renamed_file ) unless $temp_f_name eq $r +enamed_file or warn "Couldn't rename: $!\n"; } } ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Trying to rename files in directory
by Eliya (Vicar) on Feb 15, 2012 at 03:42 UTC | |
|
Re: Trying to rename files in directory
by tangent (Parson) on Feb 15, 2012 at 03:50 UTC |