Macro to delete Files and Directories

Delete all Text files in a folder

Sub DeleteTextFiles()
Kill "E:\Test*.TXT"
End Sub

Note: “E:\Test” is the file path of the folder which contains the text files and can be replaced by the file path of your choice

Delete all Word files in a folder

Sub DeleteWordDocs()
Kill "E:\Test*.DOCX"
End Sub

Delete all files in a folder

Sub DeleteAllFiles()
Kill "E:\Test\*.*"
End Sub

Delete a Directory

Sub DeleteFolder()
Kill "E:\Test*.*"
RmDir "E:\Test\"
End Sub

Note: The statement RmDir will remove only an empty directory.

How to use codes shared here?