I'm writing a VBA application which involves looping a large number of directories recursively. I am using the FindFirstFile API to to achieve this, as it offers a substantial performance boost over the FileSystemObject.
In order to remove the FSO from my code entirely, I need a routine to delete files. This has brought DeleteFile to my attention. Although I have it working - see the below code - it shows an alert to the users, asking if they'd like to delete the file. I need to remove this alert, as is possible with FSO. Application.DisplayAlerts = False does not work in this instance - most likely because it's an API call.
Is there a way to remove the alert?
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 Const FO_DELETE = &H3 Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long Private Sub TestDelete() Dim SHDirOp As SHFILEOPSTRUCT With SHDirOp .wFunc = FO_DELETE '.pFrom is file to be deleted, copied, or moved should be .pFrom = "My Path Here" 'you might also look at adding End With 'struct (Type) is now properly initialized 'call the function SHFileOperation SHDirOp End Sub