Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File::Copy failing on WIndows XP

Status
Not open for further replies.

noleander

Programmer
Joined
Mar 18, 2005
Messages
4
Location
US
Hi. I'm a long-time Unix programmer reluctantly going to the PC. In an effort to drag along my environment, I'm trying to get Perl working under XP. I've got a "hello world" working okay, but now I'm trying to copy a file:

use File::Copy;
copy ( "C:\Documents and Settings\Owner\My Documents\SpectraSonics\Scripts_n_Tools\junk1.txt" ,
"C:\Documents and Settings\Owner\My Documents\SpectraSonics\Scripts_n_Tools\junk2.txt" )
or die "copy failed $!";

The error I get when running this is:

copy failed No such file or directory at junk.txt line 2.

The source file does exist. Doesnt Perl on the PC handle back slashes?

And I also tried using system ("cp source dest") and that failed also.

Any help would be appreciated
neal
 
I changed the slashes to forward slashes and the copy command started working.

Odd that Perl does not use the slash convention of the host computer, but I can live with forward slashes on XP.
 
Try doubling your slashes. Like you I'm a Unix programmer at heart and when I work in the Windows environment I constantly curse Mr Gates for puttng the slashes the wrong way round. Perl, like C, interprets \n, for example, as new line. This means that
Code:
"C:\new directory"
would be interpreted as
Code:
C:
ew directory
To prevent this 'escape' the backslahes with a backslash to get
Code:
C:\\new directory

Columb Healy
 
Windows is not finicky about the slashes for machine paths, it will work with back or forward slashes. But perl is finicky, because as columb notes, the backslash is a special character.

You can also single-quote your path statements if you want to keep backslashes and avoid interpolation of special characters:

Code:
copy ( 'C:\Documents and Settings\Owner\My  Documents\SpectraSonics\Scripts_n_Tools\junk1.txt','C:\Documents and Settings\Owner\My Documents\SpectraSonics\Scripts_n_Tools\junk2.txt' )
   or die "copy failed  $!";
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top