Home All Groups Group Topic Archive Search About

File Copy Without Closure

Author
21 Sep 2005 2:31 PM
Roger Stenson
Hi all

During the course of a VB6 procedure a want to make a copy of an Access
database, hopefully without closing it as seems to be required by FileCopy.
I  have noted that Windows Explorer has no trouble copying an  open file.



I have included the following code in the procedure largely copied from the
Language Ref manual

It halts on the last instruction with the message "Type Mismatch"

Is there any way through this with this approach  or should I resort to
FileCopy

Thanks in anticipation



Roger Stenson



Dim f, fs, s

Dim CopyPath As String

CopyPath = Left(DBPath, Len(DBPath) - 4) & "BU" & DatePart("yyyy", Date) &
DatePart("m", Date) & DatePart("d", Date) & ".mdb"

Set fs = CreateObject("Scripting.FileSystemObject")

Set f = fs.GetFile(DBPath)

Set s = f.Copy(CopyPath)

----------

Author
21 Sep 2005 3:11 PM
Chris Dunaway
Roger Stenson wrote:

> During the course of a VB6 procedure a want to make a copy of an Access
> database, hopefully without closing it as seems to be required by FileCopy.
> I  have noted that Windows Explorer has no trouble copying an  open file.

That would be true only if the process that has the file opened, did
not open the file exclusively.

>
> Dim f, fs, s
>
> Dim CopyPath As String
>
> CopyPath = Left(DBPath, Len(DBPath) - 4) & "BU" & DatePart("yyyy", Date) &
> DatePart("m", Date) & DatePart("d", Date) & ".mdb"
>
> Set fs = CreateObject("Scripting.FileSystemObject")
>
> Set f = fs.GetFile(DBPath)
>
> Set s = f.Copy(CopyPath)

The Copy method of the file object does not return a value to my
knowledge.  What is s supposed to contain after the copy operation is
complete?

If you are using the FileSystemObject, why not use fs.CopyFile ??

VB's built in FileCopy method, according to the docs, throws an error
if the file being copied is open.  But as I alluded to earlier, if the
process that has the file opened locked the file for reading by other
processes, then you will not be able to copy it, regardless of the
method you choose.
Author
22 Sep 2005 1:18 PM
Dave
Roger

This can be done using SHFileOperation API.

This API will do lots of things like moving to the Recycle bin and showing
the file copy/move/delete animation so it is best to work out which
functions you need then write (or adapt someone elses) a wrapper to expose
what you need. You will need to add some code to trap copy failures if the
database is open with exclusive access.

Examples can be found all over the net, but an obvious first port of call
would be Randys site http://vbnet.mvps.org http://www.mvps.org/ is also a
good jumping off place for all sorts of help.

Regards
Dave O.

Show quoteHide quote
"Roger Stenson" <r.sten***@paston.co.uk> wrote in message
news:b9eYe.8613$1A.2021@newsfe1-gui.ntli.net...
> Hi all
>
> During the course of a VB6 procedure a want to make a copy of an Access
> database, hopefully without closing it as seems to be required by
> FileCopy. I  have noted that Windows Explorer has no trouble copying an
> open file.
>
>
>
> I have included the following code in the procedure largely copied from
> the Language Ref manual
>
> It halts on the last instruction with the message "Type Mismatch"
>
> Is there any way through this with this approach  or should I resort to
> FileCopy
>
> Thanks in anticipation
>
>
>
> Roger Stenson
>
>
>
> Dim f, fs, s
>
> Dim CopyPath As String
>
> CopyPath = Left(DBPath, Len(DBPath) - 4) & "BU" & DatePart("yyyy", Date) &
> DatePart("m", Date) & DatePart("d", Date) & ".mdb"
>
> Set fs = CreateObject("Scripting.FileSystemObject")
>
> Set f = fs.GetFile(DBPath)
>
> Set s = f.Copy(CopyPath)
>
> ----------
>
>