I see ysth beat me to this one, but here is the code I was working on anyway. It uses the opendir/readdir/loop method:

use strict; use warnings; use File::Spec; # for portable filename operations use File::Path; # to create the new subdirectory use File::Copy; # to move the edited file my $currentdir = '.'; my $newdir = File::Spec->catdir( $currentdir, 'newdir' ); # make the new subdirectory mkpath( $newdir ) or die "error creating $newdir"; # get all filenames in the current directory opendir( DIR, $currentdir ) or die "couldn't open $currentdir\n"; my @filenames = readdir DIR; closedir DIR; # get the program name so it's not moved if $currentdir eq '.' my ( undef, undef, $progname ) = File::Spec->splitpath( $0 ); foreach my $file (@filenames) { # add the full path to the filename my $pathfile = File::Spec->catfile( $currentdir, $file ); # skip if $file is a directory or this program if( -d $pathfile or $file eq $progname ) { next; } # process file here # move file to new subdir my $newpath = File::Spec->catfile( $newdir, $file ); move( $pathfile, $newpath ) or print "error moving $file"; }

I'm sure more experienced Monks can come up with more elegant solutions, but this works on the tests I performed.

HTH

Update: Fixed code per parv's suggestion.


In reply to Re: File::Find problems by bobf
in thread File::Find problems by hokie

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.