CopyFileEx Fails to copy & deletes target file if source file is Open


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: CopyFileEx Fails to copy & deletes target file if source file is Open

  1. #1
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263

    Unhappy CopyFileEx Fails to copy & deletes target file if source file is Open

    I have written a little backup program. When a file is open it will not copy.
    The CopyFileEx API Call Fails. I even used the COPY_FILE_OPEN_SOURCE_FOR_WRITE option.
    If I open the file first using CreateFileA for GENERIC_READ
    with Share Mode of:
    FILE_SHARED_READ OR FILE_SHARED_WRITE,
    and the CreationDisposition is: OPEN_EXISTING,
    with attributes set to: FILE_ATTRIBUTE_NORMAL
    Then the file opens successfully. Which I then close with CloseHandle.
    But still when I try to use CopyFileEx it fails to copy the file.
    What is even worse is that to old version of the file stored on the backup drive gets erased.

  2. #2
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,666
    I'm not a real big fan of the FileSystemObject, but that will copy open files.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  3. #3
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263
    The problem with that is performance.
    I went with the Windows API because of the performance benifits.
    When you are backing up a lot of files every little bit helps.

Similar Threads

  1. runtime.exec()
    By Seb in forum Java
    Replies: 7
    Last Post: 10-18-2005, 06:14 PM
  2. Replies: 0
    Last Post: 05-25-2002, 02:53 AM
  3. list of open source projects and resources
    By Anonymous in forum Open Source
    Replies: 0
    Last Post: 05-12-2002, 10:05 PM
  4. list of Open source resources + projects
    By Anonymous in forum Open Source
    Replies: 0
    Last Post: 04-24-2002, 02:20 AM
  5. File uploading / objFile.Write problem
    By Tomer Cagan in forum ASP.NET
    Replies: 1
    Last Post: 07-24-2001, 10:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center