Cestino




'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

Public Function FileDelete( FileArray 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" )'eliminare un singolo file

'oppure


ret = FileDelete("c:\prova.xx1","c:\prova.xx2","c:\prova.xx3")

'per eliminare piu file












( cestino.html )- by Paolo Puglisi - Modifica del 17/12/2023