• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1924
  • Last Modified:

Wait for 'CopyFile' to finish copying the file?

Hi,
Im using the following code to copy a file:

Windows.CopyFile(src, dst, false);

How do I wait for the file to be completely copied so that I could run it using shellexecute afterwards? I like simple code =)

Thanks.
0
createit
Asked:
createit
  • 2
2 Solutions
 
BedouinDNCommented:
Windows.CopyFile returns a boolean value.

Check the boolean value before continuing:

0
 
RatjeCommented:
Copyfile is a function and returns True or False.
In order to return a value it must have completed the action

So :

if Windows.CopyFile(src, dst, false) then
  //your shellexecute here

will do the trick
0
 
BedouinDNCommented:
*Blush* forgot that I cant use the TAB key for indentation here :-) (and the space bar will also click the submit button)

    if CopyFile(PChar(srcFile),PChar(destFile)) then
    begin
    //Do Shell execute code here
    end
    else
    begin
    //Copy failed - perform other function
    end;

Regards.
Colin..
0
 
createitAuthor Commented:
That is so weird. I tried that earlier and it seemed like the copyfile function just sent a command to copy the file and continued to the rest of my code without waiting for the file to be fully copied...But I just tried it again and it seems like it is waiting now. I have no idea why it wasnt working before...Im going to try it again in the morning with a big file to really determine if its working (after some sleep). If its still working properly (waits until the entire file is copied) Ill split the points between the two of you. Im just so curious on what I might have done differently before that it wasnt giving me the correct results.
Thanks for your help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now