Loading ...
Sorry, an error occurred while loading the content.
 

[PBML] Re: File::Copy and file globs

Expand Messages
  • daymobrew
    ... next ... want a specific selection from. So, I just replaced my copy with the ... I don t know. ... This brings up the debate of whether to implement all
    Message 1 of 2 , Apr 4, 2002
      --- In perl-beginner@y..., "Jeff Eggen" <jeggen@s...> wrote:
      > >>> daymobrew@y... 04/04/02 01:43am >>>
      > >From the File::Copy docs:
      > >"The copy function takes two parameters: a file to copy from and a
      > >file to copy to."
      > >No mention of glob here (it mentioned "FileHandle glob" on the
      next
      > >line but that is something different).
      > >So, yes you need to provice a file name for the source AND for the
      > >destination.
      >
      > That's what confused me. So, what's a FileHandle glob?
      >
      > >If you want to copy a directory tree from one place to another you
      > >can use copydir().
      >
      > No, the situation is a directory with a couple hundred files that I
      want a specific selection from. So, I just replaced my copy with the
      following:
      >
      > my @filestocopy = (`ls /directory/${files}*`);
      > foreach (@filestocopy)
      > {
      > copy("$_", "/where/I/want/it");
      > }
      >
      > Which is working.
      >
      > Thanks Damien!!
      >
      > Jeff Eggen

      > So, what's a FileHandle glob?
      I don't know.

      > So, I just replaced my copy with the following:
      This brings up the debate of whether to implement all code as perl or
      to use external utilities. You have done the latter by using 'ls'.

      To implement this in perl you could do (totally untested):

      if ( opendir( DH, '/directory' ) )
      {
      # This is one line - grep and readdir.
      @filestocopy = grep { /$files/ && -f "/directory/$_" } readdir
      (DH);

      # Could possibly put the grep/readdir line inside the '( )'.
      foreach (@filestocopy)
      {
      copy("$_", "/where/I/want/it");
      }
      }
    Your message has been successfully submitted and would be delivered to recipients shortly.