|
-
Apr 22nd, 2008, 05:38 AM
#1
Thread Starter
Frenzied Member
How to delete folder ?
I have testing directory in my computer. My directory is "Workspace". How I can delete all folder in this workspace. This workspace is become rubbish because I use this directory in my application creating new folder. So I want to empty the folders in this directory first before create new folder. How to do that?
-
Apr 22nd, 2008, 05:56 AM
#2
PowerPoster
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.
-
Apr 22nd, 2008, 06:33 AM
#3
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
-
May 12th, 2008, 10:04 AM
#4
Thread Starter
Frenzied Member
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?
-
May 12th, 2008, 11:39 AM
#5
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|