Wait for 'CopyFile' to finish copying the file?

Posted on 2005-04-28
Last Modified: 2008-01-09
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 =)

Question by:createit
    LVL 4

    Expert Comment

    Windows.CopyFile returns a boolean value.

    Check the boolean value before continuing:

    LVL 2

    Assisted Solution

    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
    LVL 4

    Accepted Solution

    *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
        //Do Shell execute code here
        //Copy failed - perform other function


    Author Comment

    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.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
    In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    733 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

    20 Experts available now in Live!

    Get 1:1 Help Now