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

Fellow Monks,
Using Activestate perl on Windows2000. I've a script which has a system call, for DOS the command would be:
copy a\b\*.txt a\
Which works fine, but putting it into a system call from a perl script was a bit more difficult.I tried a number of backslash & forward slash variations, but the one that eventually worked for was
system ("copy a\\b\\*.txt a/");
Can anybody explain to me what exactly is going on here??
Also, how could the same be achieved using the copy command. I tried:
copy("copy a\\b\\*.txt ","a/");
But got nowhere with that, any ideas I would be grateful.
Martymart

Replies are listed 'Best First'.
Re: Windows backslash problem
by Mr. Muskrat (Canon) on Jan 23, 2003 at 18:16 UTC

    I would recommend using File::Copy:

    use File::Copy; copy("a/b/*.txt","a/");

    Update: I forgot that File::Copy doesn't do globs...

    use File::Copy; my @list = <a/b/*.txt>; foreach my $file (@list) { copy($file,"a/"); }
      Hi Mr. Muskrat, I just tried your suggestion:
      use File::Copy; copy("a/b/*.txt","a/");
      unfortunately it doesn't seem to work for me. It works fine for an individual file, say:
      use File::Copy; copy("a/b/ccc.txt","a/");
      not a problem, but when the * is put in it doesn't seem to do its job. Any ideas?
Re: Windows backslash problem
by martymart (Deacon) on Jan 23, 2003 at 18:16 UTC
    sorry, spotted a typo, third code block should read copy("copy a\\b\\*.txt","a/"); no space after the *.txt
Re: Windows backslash problem
by Gilimanjaro (Hermit) on Jan 23, 2003 at 18:57 UTC
    copy("copy a\\b\\*.txt ","a/"); ^^^^^

    Can't be right, right? Looks like a copied&pasted system command, but the copy & space should leave town by dawn...