ciao a tutti.
ho un piccolissimo problema.
ho fatto un programma che mi copia la cartella documenti o desktop a mia scelta tramite due checkbox, questa copia quando finisce io nn so se l'ha fatta o cè stato qualche errore, e quindi vorrei sapere il codice per verificare se la copia è stata fatta con successo.
ecco il codice del programma:
Private Type BROWSEINFO
hOwner As Long
pidlRoot As Long
pszDisplayName As String
lpszTitle As String
ulFlags As Long
lpfn As Long
lParam As Long
iImage As Long
End Type
Private Const FO_COPY = &H2&
Private Const FOF_ALLOWUNDO = &H40&
Private Const FOF_CONFIRMMOUSE = &H2&
Private Const FOF_CREATEPROGRESSDLG = &H0&
Private Const FOF_FILESONLY = &H80&
Private Const FOF_MULTIDESTFILES = &H1&
Private Const FOF_NOCONFIRMATION = &H10&
Private Const FOF_NOCONFIRMMKDIR = &H200&
Private Const FOF_RENAMEONCOLLISION = &H8&
Private Const FOF_SILENT = &H4& 'Progress non visibile
Private Const FOF_SIMPLEPROGRESS = &H100& 'non visualizzare il nome del file
Private Const FOF_WANTMAPPINGHANDLE = &H20&
Private Type SHFILEOPSTRUCT
hwnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Long
hNameMappings As Long
lpszProgressTitle As String
End Type
Private Const BIF_RETURNONLYFSDIRS = &H1
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long
Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)
Private Declare Sub CopyMemory Lib "Kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As Any) As Long
Public Function SfogliaCartelle(ByVal Handle As Long) As String
Dim BInfo As BROWSEINFO
Dim CartellaScelta As Long
Dim PercorsoAllocato As Long
Dim PercorsoScelto As String
BInfo.hOwner = Handle
BInfo.lpszTitle = "Scegli una cartella:"
BInfo.ulFlags = BIF_RETURNONLYFSDIRS
PercorsoAllocato = SHBrowseForFolder(BInfo)
PercorsoScelto = Space$(512)
CartellaScelta = SHGetPathFromIDList(PercorsoAllocato, PercorsoScelto)
If CartellaScelta Then
SfogliaCartelle = Left$(PercorsoScelto, InStr(PercorsoScelto, Chr$(0)) - 1)
CoTaskMemFree PercorsoAllocato
Else
SfogliaCartelle = ""
End If
End Function
Public Function CopyFile(Source As String, Dest As String, AskOverwrite, Visib) As Boolean
Dim lenFileop As Long
Dim foBuf() As Byte
Dim fileop As SHFILEOPSTRUCT
lenFileop = LenB(fileop)
ReDim foBuf(1 To lenFileop)
With fileop
.hwnd = Form1.hwnd
.wFunc = FO_COPY
.pFrom = Source & vbNullChar & vbNullChar & vbNullChar
.pTo = Dest & vbNullChar & vbNullChar
If AskOverwrite = False Then .fFlags = FOF_NOCONFIRMATION 'nn chiede la sovrascrittura
If Visib = False Then .fFlags = .fFlags Or FOF_SILENT 'invisibile
.lpszProgressTitle = "Copia " & Dest & vbNullChar & vbNullChar
End With
Call CopyMemory(foBuf(1), fileop, lenFileop)
Call CopyMemory(foBuf(19), foBuf(21), 12)
CopyFile = SHFileOperation(foBuf(1)) = 0
End Function
Private Sub about_Click()
Load about1
about1.Show
End Sub
Private Sub Command1_Click()
End
End Sub
Private Sub copia_Click()
If ckdo Then x = CopyFile("C:\Documents and Settings\" & txt & "\documenti", lbl, True, True)
If ckde Then x = CopyFile("C:\Documents and Settings\" & txt & "\desktop", lbl, True, True)
If Not x Then MsgBox "Errore l'utente specificato non esiste!", vbCritical, "Errore di copia"
End Sub
e in un pulsante sfoglia metto quest'altro codice:
lbl.Caption = SfogliaCartelle(Me.hwnd)
end sub
quale il codice da inserire per vedere se la copia e avvenuta con successo????
grazie molte e spero di essere stato chiaro.
|