Delete all files in a folder

Viewed 33475

I have the below code to try search for all files in my downloads folder and then delete them all however it's returning an error message based on the kill function not having enough arguments, any ideas?

Sub Kill ()

Dim aFile As String
aFile = "C:\Test\Test\Downloads\*.*"
If Len(Dir$(aFile)) > 0 Then
    Kill aFile
End If

End Sub

Thanks,

3 Answers

You should not name macros as the in built functions. Just changing the macros with the same coding resolves the issues...

Sub Kill1 ()

Dim aFile As String
aFile = "C:\Test\Test\Downloads\*.*"
If Len(Dir$(aFile)) > 0 Then
    Kill aFile
End If

End Sub
Related