Discussion Locked

Copy an open file with VB6

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I have written a VB6 program to copy and rename a database file from my NT server, however, the FileCopy command apparently cannot copy an open file. I have a .bat file that can copy the open file. Can I call a .bat file from VB6, or is there perhaps a Windows (2000) API that I can use?

7 replies

by sl-campbell

Is the MDB opened exclusively or shared? If the first, then open it Shared instead.
I am tracking this so if it still doesn't work the post a comment to your question and not to my answer.

by sl-campbell

I doubt if this will help- the FileCopy is based off of this API There are no constants to force a copy because the file is obviously locked by another process and Windows will not allow a copy on protected files-The API function to copy files is asfollows:

Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long

Private Type SHFILEOPSTRUCT
wFunc As Long
pFrom As String
pTo As String
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As Long
End Type

Public Const FOF_NOCONFIRMATION = &H10

Public Sub API_CopyFile(ByVal sFileFrom As String, ByVal sFileTo As String, Optional ByVal bNoDelConfirm As Boolean = False)
Const FO_COPY = &H2
Const FOF_SILENT = &H4

Dim lReturn As Long
Dim SHop As SHFILEOPSTRUCT

On Error Resume Next

With SHop
.wFunc = FO_COPY
.pFrom = sFileFrom
.pTo = sFileTo
If bNoDelConfirm Then .fFlags = .fFlags + FOF_NOCONFIRMATION
End With

lReturn = SHFileOperation(SHop)

End Sub

by bojidar alexandrov

Perahps the problem is with the FileCopy function - it tries to open file exclusively when copying it...I cant remember now Windows function for file copy but you can execute the bat file with ShellExecute (WinAPI)

Regards,
Bojidar Alexandrov

This discussion is closed to new replies.