open(my $fh, $namefile) or die "$namefile: $!"; while (<$fh>) { rename ($_, "testfile$_") or warn "rname $_: $!"; } close($fh);
This does not meet the spec given, even if you chomp the lines. Even if the data file was changed to contain the current names of the files, it wouldn't meet the spec given. The names of the files pbaumgar has and the names desired cannot be reconciled by concatenation alone.
RoyCrowder's solution achieves the desired effect if the data file all follows from the example. Otherwise, keeping the file of new filenames as in the spec would be more desirable, like this minor modification to RoyCrowder's existing code:
opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!"; my @files = grep { /^\./ && -f "$some_dir/$_" } readdir(DIR); closedir(DIR); @files = sort {$a <=> $b} @files; # Ascending sort open my $names, '<', 'newnames.txt' or die "Cannot read newnames.txt: +$!\n"; foreach (@files) { my $name = <$names>; chomp $name; rename($_, $name) or warn "rename: $_ : $!"; }
In reply to Re^2: rename files
by mr_mischief
in thread rename files
by pbaumgar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |