How to copy files with white spaces?

Posted on 2005-04-13
Last Modified: 2012-06-27

How do I copy files with whitespaces? I am using ActivePERL on Windows.

I tried:

$from = "white space is here.txt";
$to = "c:/";

File::Copy::syscopy($from, $to) or warn("Cannot copy\n");

File::Copy::copy($from, $to) or warn("Cannot copy\n");

Win32::CopyFile($from, $to, 1) or warn("Cannot copy " . &cwd . "/$filename!\n");

And in all of them i get the message Cannot Copy

Any suggestions?
Question by:newaira
    LVL 69

    Expert Comment

    $from = "\"white space is here.txt\"";

    The \ means quote the next character as is, and the net effect is to enclose the path in quotes.
    LVL 3

    Author Comment

    Sorry, actually the second copy with File::Copy::copy does work, I just forgot to have
    $to = "c:/";

    instead of

    $to = "c:\";

    when I was testing.
    LVL 48

    Accepted Solution

    It will work if you do:

    File::Copy::syscopy $from, "$to$from" or warn "Can not copy $from $!\n";

    Note that syscopy actually calls Win32::CopyFile under the covers.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
    I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now