Click to See Complete Forum and Search --> : Copying a file that is open by another process.
KFayal
Oct 9th, 2000, 07:50 PM
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
Try this:
'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
KFayal
Oct 9th, 2000, 10:57 PM
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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.