Re: How to delete folder ?
add a reference to Microsoft Scripting Runtime to your project, and then use this code:
Code:
Dim oFolder As Scripting.Folder
Dim fso As Scripting.FileSystemObject
Set fso = New FileSystemObject
If fso.FolderExists("c:\temp\EmailAttachments") Then
fso.DeleteFolder "c:\temp\EmailAttachments" , True 'setting force to true
'deletes read-only file
End If
I havent tested this though.;)
Re: How to delete folder ?
Try this
Code:
Private Sub DeleteFolder(FolderPath)
Dim MyFile, MyPath, MyName
Dim Fs As Scripting.FileSystemObject
Set Fs = CreateObject("Scripting.FileSystemObject")
' Display the names that represent directories.
MyPath = FolderPath ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While MyName <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName <> "." And MyName <> ".." Then
' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
MsgBox MyPath & MyName
Fs.DeleteFolder (MyPath & MyName)
End If ' it represents a directory.
End If
MyName = Dir ' Get next entry.
Loop
End Sub
Private Sub cmdDeleteFolder_Click()
Call DeleteFolder("d:\temp\")
End Sub
Re: How to delete folder ?
Sometimes the folder I try to delete is in used .So I can't delete it.
So How I can ignore this?
Re: How to delete folder ?
You can't ignore it. You have to wait until it is not in use.
If you delete something that someone else is currently using, you will generate an error on their end, which, I'm sure, would confuse the heck out of them.