Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Copy Status 1

Status
Not open for further replies.

Quros

Programmer
May 31, 2001
20
GB
Hi,

Does anymody know of a file copy method I can use from within VB which will give me some kind of progress? Like explorer does when copying large files, or files over a slow network connection.

Any help greatly appreciated.

Quros.
 
From an old program I wrote.
Hope I included everything you need.

Private Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Boolean
hNameMappings As Long
lpszProgressTitle As String
End Type

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

Private Const FO_COPY = &H2
Private Const FOF_ALLOWUNDO = &H40
Private Const FOF_NOCONFIRMATION = &H10 ' Don't prompt the user.
Private Const FOF_NOCONFIRMMKDIR = &H200 ' don't confirm making any needed dirs


Public Function CopyFile(ByVal sSource As String, _
ByVal sDest As String, _
Optional bNoConfirmation As Boolean = True, _
Optional nTries As Long = DEFAULTTRIES, _
Optional nWait As Single = DEFAULTWAIT) As Boolean
Dim sh_op As SHFILEOPSTRUCT
Dim nAttempts As Long

On Error GoTo ERRORHANDLER
CopyFile = False
nAttempts = 0

TRYAGAIN:

With sh_op
.hWnd = 0
.wFunc = FO_COPY
.pFrom = sSource & vbNullChar & vbNullChar
.pTo = sDest & vbNullChar & vbNullChar
If bNoConfirmation Then
.fFlags = FOF_NOCONFIRMATION Or FOF_NOCONFIRMMKDIR
Else
.fFlags = FOF_NOCONFIRMMKDIR
End If
End With

If SHFileOperation(sh_op) = 0 Then
CopyFile = True
Else
If sh_op.fAnyOperationsAborted Then
msProblem = "User aborted operation."
Else
msProblem = "Unknown error. Check network connections and/or space available in destination."
End If
CopyFile = False
End If

Exit Function

ERRORHANDLER:
nAttempts = nAttempts + 1
If nAttempts <= nTries Then
waitSeconds nWait
Resume TRYAGAIN
Else
msProblem = &quot;Unable to copy &quot; & sSource & &quot; to &quot; & sDest & _
&quot; (&quot; & Err.Number & &quot;: &quot; & Err.Description & &quot;)&quot;
Exit Function
End If
End Function

 
Excellent - That works well. Thanks for the help.

Quros
 
sorry for this english but i don't speek
is it a function in Vb of in Win where i can copy a file and where i can know the statut of this copy?
I have a probleme whis a &quot;machine&quot;??
it hase a pil of 300 file.I must copy file / file
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top