cmeena has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, I have a perl script running on my Windows XP machine that tries to copy a file that ends in .gz from a windows share. The DOS copy command would be copy \\amsepi01\logs$\*.gz d:\temp\logs I tried using back quotes with \\ or double quotes, but nothing seems to work. Any ideas on how I can accomplish this?

Replies are listed 'Best First'.
Re: copying multiple files from a share
by gaal (Parson) on Mar 09, 2005 at 21:16 UTC
    Did you manage to copy multiple files not from a share?

    You need to do the same thing here. Two things to keep in mind: Perl-the-language doesn't have a command to copy multiple files; you need to use a glob or possibly use readdir and choose files yourlsef; and (as you are aware) you need to escape the backslash (or just use a forward slash instead).

    Something like this should work, but is untested.

    use File::Copy; my $to = 'd:/temp/logs/"; foreach my $from (glob '//amsepi01/logs$/*.gz') { copy($from, $to) or die "copy: $!"; }
      The above code worked. All I have to change was escape the $ sign like logs\$. Thanks for your help.
        You're welcome!

        I'm wondering why you needed to escape the $ though, since it was single-quoted.

Re: copying multiple files from a share
by data64 (Chaplain) on Mar 09, 2005 at 21:16 UTC

    Could you show us the code that you have so we can try to help you with it ?

    You might want to try single quote around the path so Perl does not try to interpolate characters in the path.

    I was going to suggest using File::Copy but I am not sure whether it supports UNC paths.