I have a access data base in c:\ i need to copy in server dir.
the dimension of file is approx 580 mb.
wuth the copyfile or file copy the time of transferin is very very big!!
exists a method to speed up thi soperation?
Goggoling ... user suggest to use API but sure not for me!
trnsfer from c:\ to server dir
-
- Administrator
- Posts: 78642
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: trnsfer from c:\ to server dir
I'm not sure a Windows API function would be faster. But you could try it. Copy the following code to the top of a module, above all Subs and Functions:
Use like this:
Code: Select all
Public Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" _
(ByVal lpExistingFileName As String, _
ByVal lpNewFileName As String, _
ByVal bFailIfExists As Long) As Long
Code: Select all
Dim strSourceFile As String
Dim strTargetFile As String
strSourceFile = "C:\Databases\MyDatabase.mdb"
strTargetFile = "\\MyServer\MyShare\MyFolder\MyDatabase.mdb"
If CopyFile(strSourceFile, strTargetFile, False) = 0 Then
MsgBox "Copy failed!", vbInformation
End If
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4374
- Joined: 26 Apr 2010, 17:36
Re: trnsfer from c:\ to server dir
Your code work very very fats!HansV wrote:I'm not sure a Windows API function would be faster. But you could try it. Copy the following code to the top of a module, above all Subs and Functions:
Use like this:Code: Select all
Public Declare Function CopyFile Lib "kernel32" Alias "CopyFileA" _ (ByVal lpExistingFileName As String, _ ByVal lpNewFileName As String, _ ByVal bFailIfExists As Long) As Long
Code: Select all
Dim strSourceFile As String Dim strTargetFile As String strSourceFile = "C:\Databases\MyDatabase.mdb" strTargetFile = "\\MyServer\MyShare\MyFolder\MyDatabase.mdb" If CopyFile(strSourceFile, strTargetFile, False) = 0 Then MsgBox "Copy failed!", vbInformation End If
But to have a good velocity i need to kill before the destination file if exists....
Gogooling....
Option Explicit
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Const FO_COPY = &H2
Const FO_DELETE = &H3
Const FO_MOVE = &H1
Const FO_RENAME = &H4
Const FOF_ALLOWUNDO = &H40
Const FOF_SILENT = &H4
Const FOF_NOCONFIRMATION = &H10
Const FOF_RENAMEONCOLLISION = &H8
Const FOF_NOCONFIRMMKDIR = &H200
Const FOF_FILESONLY = &H80
Private Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAborted As Boolean
hNameMaps As Long
sProgress As String
End Type
Private Sub cmdCopy_Click()
Dim result As Long, fileop As SHFILEOPSTRUCT
Dim FILE_PATH As String
FILE_PATH = "C:\TEMP\B.mdb"
With New FileSystemObject
If .FileExists(FILE_PATH) Then
.DeleteFile FILE_PATH
End If
End With
With fileop
'.hwnd = Me.hwnd
.wFunc = FO_COPY
.pFrom = "C:\ASS_MF\DATABASE\B.mdb"
.pTo = "C:\TEMP\B.mdb"
.fFlags = FOF_NOCONFIRMMKDIR
End With
result = SHFileOperation(fileop)
If result <> 0 Then
MsgBox Err.LastDllError
End If
End Sub
but this code show the pop up with the tipical progressbar of window .. is possible to suppress....?
-
- Administrator
- Posts: 78642
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: trnsfer from c:\ to server dir
Change
.fFlags = FOF_NOCONFIRMMKDIR
to
.fFlags = FOF_NOCONFIRMMKDIR Or FOF_SILENT
.fFlags = FOF_NOCONFIRMMKDIR
to
.fFlags = FOF_NOCONFIRMMKDIR Or FOF_SILENT
Best wishes,
Hans
Hans
-
- PlatinumLounger
- Posts: 4374
- Joined: 26 Apr 2010, 17:36
Re: trnsfer from c:\ to server dir
HansV wrote:Change
.fFlags = FOF_NOCONFIRMMKDIR
to
.fFlags = FOF_NOCONFIRMMKDIR Or FOF_SILENT
Hans ... fot you using this code i can get advantage in order of speeding tyime time/copy respect your code?
-
- Administrator
- Posts: 78642
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: trnsfer from c:\ to server dir
The code that you posted is completely different from the code that I posted. You cannot combine or merge them.
Best wishes,
Hans
Hans