Deleting files and folders

G

Guest

Hi can anybody help

I need some code to delete everything in a folder and the folder itself.
Sometime the folder may contain both files and folders or may even be empty.

myPathDel = "C:\test"
Kill myPathDel & "\*.*"
RmDir (myPathDel)

I have tried variations of theses and nothing seems to work. In the example
the folder "test" may be empty or may contain a combination of files and
folders, I need a way of deleting this no matter what it conatins.

Thanks In advance

Matt
 
D

Douglas J Steele

The problem would be if there are folders: the Kill statement only works on
files.

You may find it easier to use FSO (FileSystemObject) in this case:

Dim fsoCurr As Object

Set fsoCurr = CreateObject("Scripting.FileSystemObject")
fsoCurr.DeleteFolder "C:\test", True
Set fsoCurr = Nothing
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top