|
-
Feb 22nd, 2002, 04:59 PM
#1
How do I delete a folder including files?
How do I delete a folder including files in a code?
-
Feb 22nd, 2002, 05:17 PM
#2
Frenzied Member
DeleteFolder Method
Description
Deletes a specified folder and its contents.
Syntax
object.DeleteFolder folderspec[, force]
The DeleteFolder method syntax has these parts:
Part Description
object Required. Always the name of a FileSystemObject.
folderspec Required. The name of the folder to delete. The folderspec can contain wildcard characters in the last path component.
force Optional. Boolean value that is True if folders with the read-only attribute set are to be deleted; False (default) if they are not.
Remarks
The DeleteFolder method does not distinguish between folders that have contents and those that do not. The specified folder is deleted regardless of whether or not it has contents.
An error occurs if no matching folders are found. The DeleteFolder method stops on the first error it encounters. No attempt is made to roll back or undo any changes that were made before an error occurred.
-
Feb 22nd, 2002, 05:26 PM
#3
Frenzied Member
Just an example:
VB Code:
Private Sub Command1_Click()
Set fs = CreateObject("Scripting.FileSystemObject")
fs.Deletefolder "c:\MyFolder", True
End Sub
-
Feb 27th, 2002, 12:18 PM
#4
Why doesen't this code work with NT? It works with Win98?
VB Code:
Dim fso As New FileSystemObject
Dim fldr As Folder
Private Sub Command1_Click()
Set fldr = fso.GetFolder("C:\Winnt\Test")
fldr.Delete True
End Sub
-
Feb 27th, 2002, 12:23 PM
#5
Try this
VB Code:
Private Sub DeleteFolder(FolderPath)
'Purpose: This function will delete all the folder(s) and its
'contents under the root folder. All you need to do is to pass in
'the Path as a Parameter
'Usage: Call DeleteFolder("d:\temp\")
'From: [url]www.vbcode.com[/url] by Dan Liu
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
-
Feb 27th, 2002, 12:46 PM
#6
Hack,
Does this code work with NT? What's the differens between this code and the code i suggested?
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
|