in reply to Renaming files sequentially into directory
Simple method (brute force):
#!/usr/bin/env perl use strict; use warnings; my @files = ( '000001.OrderID.html', '000002.OrderID.cgi', '000004.OrderID.js', '000005.OrderID.txt', '000006.OrderID.cgi', 'OrderID.master' ); my $i = 1; for my $infile (sort grep /^\d{6}\./, @files) { my $repl = sprintf ("%6.6i", $i++); (my $outfile = $infile) =~ s/^\d{6}/$repl/; rename $infile, $outfile; }
You can replace the initial set-up of @files with a glob.
Update: comma was absent from penultimate line.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Renaming files sequentially into directory
by Magnolia25 (Sexton) on Sep 19, 2018 at 14:55 UTC | |
by hippo (Archbishop) on Sep 19, 2018 at 15:13 UTC |