copy error

J

jtbutlerhvb

When I try to copy a file I get the message 'No such file or
directory'. I know the file is there and I know the path is correct
because in fact the file does copy. However some of my files are not
copying correctly and I am trying to figure out why so I am logging
everything.

#here is my code
for () {
....

$BAK->logMsg( "Copying $today\\$move_cube_name[4] to
$yesterday\\$move_cube_name[4]" .
copy("$today\\$move_cube_name[4]","$yesterday\\$move_cube_name[4]") .
$!) ;
#reset $! each time through loop
$! = '';

....
}

The above code is logged and it produces this output but the file is
copied. It also returns a '1' which I dont not understand since it
copied. Shouldnt it be '0'?

Copying D:\cognos_cubes\mmt\Today\Funding View.mdc to
D:\cognos_cubes\mmt\Yesterday\Funding View.mdc1No such file or
directory
 
I

it_says_BALLS_on_your forehead

When I try to copy a file I get the message 'No such file or
directory'. I know the file is there and I know the path is correct
because in fact the file does copy. However some of my files are not
copying correctly and I am trying to figure out why so I am logging
everything.

#here is my code
for () {
...

$BAK->logMsg( "Copying $today\\$move_cube_name[4] to
$yesterday\\$move_cube_name[4]" .
copy("$today\\$move_cube_name[4]","$yesterday\\$move_cube_name[4]") .
$!) ;
#reset $! each time through loop
$! = '';

...
}

The above code is logged and it produces this output but the file is
copied. It also returns a '1' which I dont not understand since it
copied. Shouldnt it be '0'?

Copying D:\cognos_cubes\mmt\Today\Funding View.mdc to
D:\cognos_cubes\mmt\Yesterday\Funding View.mdc1No such file or
directory

i would try using Copy in a manner consistent with the synopsis:
http://search.cpan.org/~nwclark/perl-5.8.7/lib/File/Copy.pm
 
P

Paul Lalli

When I try to copy a file I get the message 'No such file or
directory'. I know the file is there and I know the path is correct
because in fact the file does copy. However some of my files are not
copying correctly and I am trying to figure out why so I am logging
everything.

#here is my code
for () {
...

$BAK->logMsg( "Copying $today\\$move_cube_name[4] to
$yesterday\\$move_cube_name[4]" .
copy("$today\\$move_cube_name[4]","$yesterday\\$move_cube_name[4]") .
$!) ;
#reset $! each time through loop
$! = '';

Not enough. Read up on perldoc perlvar to see how and when $! is
actually set. You *cannot* rely on the value of $! after a successful
system call. That means you can't count on it being any particular
value, or on it not having a value. You can *only* trust the value of
$! after a failed system call.

The format of your code is just plain messy. Consider:
$BAK->logMsg("Copying $today/$move_cube_name[4] to $yesterday/");
copy ("$today/$move_cube_name[4]", $yesterday) or
$BAK->logMsg("Copy failed: $!");
The above code is logged and it produces this output but the file is
copied. It also returns a '1' which I dont not understand since it
copied. Shouldnt it be '0'?

You are confusing copy() with system(). Read the docs for File::Copy -
"All functions return 1 on success, 0 on failure"

Hope this helps,
Paul Lalli
 
X

xhoster

When I try to copy a file I get the message 'No such file or
directory'. I know the file is there and I know the path is correct
because in fact the file does copy. However some of my files are not
copying correctly and I am trying to figure out why so I am logging
everything.

#here is my code
for () {
...

$BAK->logMsg( "Copying $today\\$move_cube_name[4] to
$yesterday\\$move_cube_name[4]" .
copy("$today\\$move_cube_name[4]","$yesterday\\$move_cube_name[4]") .
$!) ;
#reset $! each time through loop
$! = '';

You are inspecting $! unconditionally. The contents of $! only make sense
if the call actually failed. So what you are seeing is that somewhere
along the line, something that "copy" does is failing with that message,
but the "copy" itself does not fail, presumably because it successfully
recovers from the error.

The above code is logged and it produces this output but the file is
copied. It also returns a '1' which I dont not understand since it
copied. Shouldnt it be '0'?

Have you read the documentation for the module you are using? What did
it say about the return value of "copy".

Xho
 
J

jtbutlerhvb

Do I need to reset $! each time through the loop so if it does fail it
doesnt log the same errors for the rest of the files even though they
may be successful?

ie: $! = ' ' ;
 
I

it_says_BALLS_on_your forehead

Do I need to reset $! each time through the loop so if it does fail it
doesnt log the same errors for the rest of the files even though they
may be successful?

ie: $! = ' ' ;

i've never heard of anyone doing that.
 
X

xhoster

Do I need to reset $! each time through the loop so if it does fail it
doesnt log the same errors for the rest of the files even though they
may be successful?

No. You should only look at $! when the "copy" call itself fails. If the
call fails, $! will be set appropriately. If the call succeeds, then it
doesn't matter what $! is set to, as you shouldn't be looking at it.
Resetting $! is (in this case) useless.

Also, you should quote some context when you reply to someone.

Xho
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top