in reply to Re^3: File NCopy concat
in thread File NCopy concat

Try using File::Copy instead. File::NCopy seems to be broken.

Update: the following illustrates the issue:

use strict; use warnings; use File::Copy; use File::NCopy; use constant FILENAME_1 => 'File with spaces in the name.txt'; use constant FILENAME_2 => 'File with spaces in the name2.txt'; use constant FILENAME1 => 'Filename.txt'; use constant FILENAME2 => 'Filename2.txt'; open outFile, '>', FILENAME1; print outFile "Some text in non-spaced out file\n"; close outFile; open outFile, '>', FILENAME_1; print outFile "Some text in the spaced out file\n"; close outFile; File::NCopy::copy (FILENAME1, FILENAME2) or warn "Non-spaced to non-sp +aced failed with NCopy\n"; File::NCopy::copy (FILENAME_1, FILENAME2) or warn "Spaced to non-space +d failed with NCopy\n"; File::NCopy::copy (FILENAME1, FILENAME_2) or warn "Non-spaced to space +d failed with NCopy\n"; File::NCopy::copy (FILENAME_1, FILENAME_2) or warn "Spaced to spaced f +ailed with NCopy\n"; File::Copy::copy (FILENAME1, FILENAME2) or warn "Non-spaced to non-spa +ced failed with Copy\n"; File::Copy::copy (FILENAME_1, FILENAME2) or warn "Spaced to non-spaced + failed with Copy\n"; File::Copy::copy (FILENAME1, FILENAME_2) or warn "Non-spaced to spaced + failed with Copy\n"; File::Copy::copy (FILENAME_1, FILENAME_2) or warn "Spaced to spaced fa +iled with Copy\n";

prints:

Spaced to non-spaced failed with NCopy Spaced to spaced failed with NCopy

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^5: File NCopy concat (glob)
by ikegami (Patriarch) on Sep 15, 2006 at 05:08 UTC
    File::NCopy's copy's argument is a glob pattern, not a file name. This pattern is passed to glob, which considers spaces to be pattern seperators, not literals. Refer to the passage I emphasised in the following snippet from File::Glob's documentation:

    Since v5.6.0, Perl's CORE::glob() is implemented in terms of [File::Glob's] bsd_glob(). Note that they don't share the same prototype — CORE::glob() only accepts a single argument. Due to historical reasons, CORE::glob() will also split its argument on whitespace, treating it as multiple patterns, whereas bsd_glob() considers them as one pattern.

    Update: File::NCopy works if you execute the following before calling copy:

    { package File::NCopy; use File::DosGlob qw( glob ); }

    And if the spaces are backslashed (or quoted).
    And if / is used as the path seperator on Windows.

    $filename = 'c:/directory\\ name/file\\ name.txt'; $filename = '"c:/directory name/file name.txt"'; $filename = 'c:/"directory name"/"file name.txt"';

    Truly, File::NCopy should be used with care if not considered outright broken. At the very least, it would be best if File::NCopy used bsd_glob rather than glob.