Maybe this will help you?
I don't see a requirement for recursive copying. That is possible and not that much harder.

The basic idea is to create a hash of the .ext's and then use that to either print that table or create a directory for each .ext.

Read the directory(s) all at once, create a hash table and use that to do the copies.

#!usr/bin/perl -w use strict; my $directory = 'C:/PerlTemp'; opendir (DIR, $directory) or die "unable to open $directory\n"; my %ext2files; #hash of array for each extension #.pl => name, .txt => name etc. foreach my $file (readdir DIR) { next if ($file =~ /^\./); #skip . and .. directories my ($ext) = ($file =~ /\.(\w+)$/)[0]; #get "xxx/yyy.ext" next unless defined $ext; # no ".extension" #now keep track of .ext to files... push @{$ext2files{$ext}},$file; } foreach my $ext (sort keys %ext2files) { # this prints the .ext ending and the number of files. # More than one syntax can do this, but I hope that # this is understandable... print "$ext \t", scalar @{$ext2files{$ext}}," files\n"; #it is possible to use the printf() formatting strings #in Perl. I didn't use that here, but it is possible. } __END__ PL 3 files SCP 1 files TXT 1 files bak 1 files bat 4 files bin 1 files c 28 files cav 1 files cmdline 1 files cpp 1 files csv 4 files dat 8 files db 4 files dbi 1 files doc 4 files exe 23 files h 2 files html 9 files ico 1 files ini 1 files jpg 1 files new 1 files out 2 files p 1 files pdf 3 files pl 1113 files pll 2 files pm 2 files script 1 files stackdump 3 files temp 1 files txt 173 files txtC 1 files xls 1 files xml 6 files zip 2 files Process completed successfully

In reply to Re: Perl - Copy files to a newly created folder by Marshall
in thread Perl - Copy files to a newly created folder by Benichouniev

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.