in reply to rename files
You don't have to use a separate file of sorted file names. You can use the code above or a variation there of to get the job done. In reading your post I saw you wanted the files not to correspond to their number (ie: 2 != testfile2, 2 == testfile1). This can be done by keeping an incremental count. If you want to keep the separate file of sorted filenames just ignore the first part.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 my $count = 1; foreach (@files) { rename($_, "testfile$count") or warn "rename: $_ : $!"; $count = $count + 1; }
|
|---|