Using API to copy files

M

Mike

I wrote a file syncronization program to compare and copy
multiple projects between my PC and the server (some 24
projects with almost 1000 files today, but the number
grows every day). It works great, and as far as I'm
concerned, the speed is fine, but I was told by a co-
worker that using API can copy files faster than the
FileCopy function in VBA. Is this true? How much faster
can it work? Does anyone have sample code to do this?
And while I'm here, is there and API routine that works
faster than the Kill function? My knowledge of API can
fit on the head of a pin, so details would be apreciated.
Thanks.
 
H

Harald Staff

Hi Mike

You will find everything on this and more on Randy Birch's pages, suggest you start here:
http://www.mvps.org/vbnet/code/callback/filebackupcallback.htm

Note that his code is VB6 so the components are not identical to VBA, that's easily
edited, and that some API things are NT family spesific.

As for speed I dare not guess. But Mr Birch's solutions are not slower than necessary.
 
M

Mike

That site did have a bit too much info for my needs and it
took a while to weed out the one simple function I needed,
but the other info may come in handy in the future.

Public Declare Function CopyFile Lib "kernel32"
Alias "CopyFileA" _
(ByVal lpExistingFileName As String, _
ByVal lpNewFileName As String, _
ByVal bFailIfExists As Long) As Long

Called using:
CopyFile SourceFile, TargetFile, 0

And after several test runs, my sync routine now appears
to run ~20% faster than before so this was quite worth the
effort. Thank you.

-----Original Message-----
Hi Mike

You will find everything on this and more on Randy
Birch's pages, suggest you start here:
http://www.mvps.org/vbnet/code/callback/filebackupcallback ..htm

Note that his code is VB6 so the components are not
identical to VBA, that's easily
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top