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

Hi, Whats the easiest way to copy a file, $FileName, from the current directory to "\\somecomputer\folder\here\" not using the "use File::Copy;" module?

Replies are listed 'Best First'.
Re: File Copy
by Ionitor (Scribe) on Jul 22, 2002 at 17:56 UTC
    As a related question, what's the easiest way of writing Perl code without whitespace?

    Seriously, what is your reason for wanting to avoid a relatively easy, platform-independent method like File::Copy? If there's really a good reason, and since you seem to be using a Windows network copy, you could just use:

    `copy $FileName \\\\somecomputer\\folder\\here\\`;
    system('copy', $FileName, '\\\\somecomputer\\folder\\here\\');
    You need to doubled-up backslashes to avoid escaping issues.
Re: File Copy
by broquaint (Abbot) on Jul 22, 2002 at 17:59 UTC
    open(my $src, '<', $FileName) or die("ack - $!"); open(my $dest, '>', '/somecomputer/folder/here') or die("ack - $!"); binmode($src); binmode($dest); print $dest $_ while <$src>;
    Perhaps. But why on vroom's $theme_coloured monastery would you want to *avoid* using File::Copy?


Re: File Copy
by simeon2000 (Monk) on Jul 22, 2002 at 18:13 UTC
    Not using File::Copy? You're wasting your own time. However, if you can't get your system's copy command to work right, you could always just open from one and print to another:

    open SRC, $infile; open DEST, ">$output"; # for handicapped systems binmode(SRC); binmode(DEST); while (<SRC>) { print DEST $_; } close DEST; close SRC;
    Not EASY, but when you refuse to use the EASY way (File::Copy), you gotta fill a few lines...

    "Falling in love with map, one block at a time." - simeon2000

Re: File Copy
by fuzzyping (Chaplain) on Jul 22, 2002 at 17:48 UTC
    Can you be more specific? Are you looking for a module with particular features, or just a vanilla copy? If the latter, have you tried system()?


    Update: See Ionitor's detailed example below.
      this would just be a vanilla copy of the file. I Tried the system call, but i counldn't get the syntax correct. I was looking for something along the lines of: system "copy $FileName \\somecomputer\folder\there\" how off am I on the syntax? Thanks for the help.
        If I remember correctly, the system function is of the form:
        So you might have better luck if you split up the command from the arguments. It's worth a try.
Re: File Copy
by silent11 (Vicar) on Jul 22, 2002 at 22:08 UTC
    As far as the easiest way, it depends on what you are doing. I see that you are in a Windows environment. It may be worth your time looking into Robocopy.