In article <[EMAIL PROTECTED]> wrote "P0r0ng"
<[EMAIL PROTECTED]>:
> hi list.
> supposing i have a directory containing these files: nat_10-full.xml.afp
>nat_10.xml.afp
> nat_1-full.xml.afp nat_1.xml.afp
> nat_2-full.xml nat_2.xml
> nat_3-full.xml nat_3.xml
> nat_4-full.xml nat_4.xml
> nat_5-full.xml nat_5.xml
> nat_6-full.xml nat_6.xml
> nat_7-full.xml nat_7.xml
> nat_8-full.xml.afp nat_8.xml.afp
> nat_9-full.xml nat_9.xml
> you can see that there are some files with dual extensions. my problem is i want to
>erase all
> files with dual extensions and re-arrange the array of files in a new order, like so:
> ...
If I understand you correctly, you want to do 3 steps:
1. Delete all files with double extensions.
2. Sort the remaining files for their number after nat_.
3. Rename the remaining files correspondending to the sort place.
Let's try:
chdir $your_directory; # I assume you're already in the right directory
unlink foreach (<*.*.*>); # delete all files with dual extensions
# Your sort routine
my $sort_for_nat_number =
sub { "$a$b" =~ /nat_(\d+).*nat_(\d+)/; $1 <=> $2 };
# Sort all full files and simple files seperatly
my @full_files = sort $sort_for_nat_number (<*-full.xml>);
my @files = sort $sort_for_nat_number grep {$_ !~ /full/} (<*.xml>);
# Now renames
rename $full_files[$_-1], "nat_$_-full.xml"
for (1 .. scalar @full_files);
rename $files[$_-1], "nat_$_.xml" for (1.. scalar @files);
Best Wishes,
Andrea
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]