Results 1 to 3 of 3

Thread: Copying a file that is open by another process.

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    San Diego, CA
    Posts
    2

    Lightbulb

    I know I have seen this code before, but I can't find it anywhere. I have seen code where you can copy a file that is already open by another process. For example, if you wanted to copy an open .MDB. I recall that there were a few API calls required to do it. Simply using FileCopy does not do it. I just don't recall which API calls were required and for the life of me, I can't remember where I saw it last.

    Ken

  2. #2
    Guest
    Try this:

    Code:
    'Author: Im_[B]0ReD
    'Origin: http://www.planet-source-code.com
    'Purpose:  A substitute 'FileCopy'
    'Version: VB4+ 
    
    Function CopyFile(srcFile As String, dstFile As String)
        'this copies a file byte-for-byte
        'or you could just use good old FileCopy
        '     :-)
        On Error Resume Next 'If we Get an error, keep going
        Dim Copy As Long, CopyByteForByte As Byte 'the variables
        Open srcFile For Binary Access Write As #1 'open the destination file so we can write To it
        Open dstFile For Binary Access Read As #2 'open the source file so we can read from it
    
    
        For Copy = 1 To LOF(2) 'Copy The SourceFile Byte-For-Byte
            Put #1, , CopyByteForByte 'Put the byte In the destination file
        Next Copy 'stop the Loop
        MsgBox "Done!"
    End Function

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Location
    San Diego, CA
    Posts
    2

    Thanks for your suggestion

    Matthew,
    Thanks for your suggestion.. I forgot to mention that all forms of 'Open' on the file fails as well with error 70, "Permission Denied"

    Ken

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width