<code>Kopiera filer med API, hur vet jag om något gått fel?
Public 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 Long ' only used if FOF_SIMPLEPROGRESS, sets dialog title
End Type
Public Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
' Available Operations
Public Const FO_COPY = &H2 ' Copy File/Folder
Public Const FO_DELETE = &H3 ' Delete File/Folder
Public Const FO_MOVE = &H1 ' Move File/Folder
Public Const FO_RENAME = &H4 ' Rename File/Folder
' Flags
Public Const FOF_ALLOWUNDO = &H40 ' Allow to undo rename, delete ie sends to recycle bin
Public Const FOF_FILESONLY = &H80 ' Only allow files
Public Const FOF_NOCONFIRMATION = &H10 ' No File Delete or Overwrite Confirmation Dialog
Public Const FOF_SILENT = &H4 ' No copy/move dialog
Public Const FOF_SIMPLEPROGRESS = &H100 ' Does not display file names
</code>
<code>
Dim op As SHFILEOPSTRUCT
With op
.wFunc = FO_COPY ' Set function
.pTo = "C:\test\text2<>.txt" ' Set new path <---medvetet fel filnamn för test
.pFrom = "C:\test\text1.txt" ' Set current path
.fFlags = FOF_SILENT
End With
' Perform operation
SHFileOperation op
</code>
Denna kod använder jag för att kopiera filer. Jag bestämmer flaggan till FOF_SILENT för att slippa få upp dialogruta för varje fil om något går snett (massa filer att kopiera), men om jag ändå vill samla in dessa fel till sammanställning efteråt, alltså orsak och vilken fil det handlar om... går det?