Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete folders and subfolders

Status
Not open for further replies.

GP

IS-IT--Management
Jan 14, 2002
61
GB
I have used the script off the KB on tek-tips but when I run the script it deletes all files and subfolders but not the main folder and gives an error "run-time '76' Path not found

Script:


Sub DeleteFolder(strNewDir)
' ***********************************************************
' *** This will delete a folder even if it contains files ***
' *** Use With Caution ***
' ***********************************************************
Dim fso

'Dim fol As String
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(strNewDir) Then
fso.DeleteFolder strNewDir
Else
MsgBox strNewDir & " does not exist or has already been deleted!" _
, vbExclamation, "Folder not Found"
End If

End Sub

(strNewDir = "C:\CD240104\"
 
Hi GP,

Try it with strNewDir = "C\CD240104" (i.e. without the trailing backslash).

Enjoy,
Tony

------------------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading FAQ222-2244 before you ask a question.
 
Tried that but I get a different error

runtime error 76 permission denied
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top