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

Re: File::Copy and file globs

Expand Messages
  • daymobrew
    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
    Message 1 of 2 , Apr 3, 2002
      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

      If you want to copy a directory tree from one place to another you
      can use copydir().

      Here is code I wrote to copy the file in one dir to another:
      # Copy the files in one directory to the specified directory. Sub
      directories are NOT copied.
      sub CopyOneDir( $$ )
      my ( $From, $To ) = @_;

      mkpath( "$To" ) if ( ! -d "$To" );

      ClearSingleDir( "$To" );

      if ( -d "$From" )
      if ( opendir( FROM, "$From" ) )
      my $File;
      while ( $File = readdir( FROM ) )
      if ( -f "$From/$File" )
      copy( "$From/$File", "$To/$File" );
      closedir( FROM );

      # Clear the contents of the specified directory.
      sub ClearSingleDir( $ )
      my $Dir = $_[ 0 ];

      if ( -d "$Dir" )
      if ( opendir( DIR, "$Dir" ) )
      my $File;
      while ( $File = readdir( DIR ) )
      if ( -f "$Dir/$File" )
      chmod( 0777, "$Dir/$File" );
      unlink( "$Dir/$File" );
      closedir( DIR );


      --- In perl-beginner@y..., "Jeff Eggen" <jeggen@s...> wrote:
      > Hi,
      > I'm a little unclear as to the options available for parameters for
      the File::Copy::copy routine. I'm trying to put in a file glob, like
      > copy("/software_patches/solaris/${directory}/${patch}
      *", "/software_patches/solaris/${directory}/Sol8Patches/") or
      die "blagh: $!";
      > and I get the "No such file or directory at ..." error. Do I have
      to specify a file for the destination? I was hoping the directory
      would be enough, like the cp command in *nix. Or is the problem that
      I can't use the file glob as the first parameter? I can run commands
      from the shell using that glob structure and it finds stuff, so I
      know files are there that fit the requirements, if the glob is used
      properly. File::Copy's documentation doesn't really have an example
      of a glob.
      > Any help is appreciated. I can attach the whole script if needed:
      I didn't here, because everything else seems to work except the copy
      statement above, and various print statements seem to indicate that
      the variables are what I'm looking for. I was just hoping someone
      would recognize a wrongness with the copy command above.
      > Thanks,
      > Jeff Eggen
    Your message has been successfully submitted and would be delivered to recipients shortly.