'Dichiarazioni e funzione da inserire in un modulo Bas
Public Const FO_DELETE As Long = &H3 Public Const FOF_ALLOWUNDO As Long = &H40 Type SHFILEOPSTRUCT hwnd As Long wFunc As Long pFrom As String pTo As String fFlags As Long fAnyOperationsAborted As Long hNameMappings As Long lpszProgressTitle As String End Type Declare Function SHFileOperation Lib "Shell32.dll" _ Alias "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long 'Funzione: Public Function FileDelete(xlstFileName As Variant) As Long Dim I As Integer Dim xFileName As String Dim FileOp As SHFILEOPSTRUCT For I = LBound(xlstFileName) To UBound(xlstFileName) xFileName = xFileName & xlstFileName(I) & VbNullChar Next xFileName = xFileName & VbNullChar With FileOp .wFunc = FO_DELETE .pFrom = XfileName .fFlags = FOF_ALLOWUNDO End With FileDelete = SHFileOperation(FileOp) End Function 'da utilizzare nel seguente modo: Dim ret As Long ret = FileDelete("c:\prova.xx1" )'per eliminare un singolo file 'oppure ret=FileDelete(Array("c:\nomefile1.xxx", _ "c:\nomefile2.sss", "c:\ecc.ec=c")) |