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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem deleting folder 1

Status
Not open for further replies.

UnsolvedCoding

Technical User
Jul 20, 2011
424
US
Hey guys -

I wrote a sub that creates a folder to hold files and then when its done I want to delete the folder so the computer doesn't get bogged down with pointless information.

Problem - I keep getting permission denied when I try to delete the file and I think its because its on the C drive. The sub folders get deleted and recreated as needed during the process but the main folder is giving me trouble.

Does anyone know how to delete a folder from the C drive?

Here's the current code -

Sub Delete_Folder()

'Delete whole folder without removing the files first

Dim FSO As Object
Dim MyPath As String

Set FSO = CreateObject("scripting.filesystemobject")

MyPath = "C:\Pending_Temp"

If FSO.FolderExists(MyPath) = False Then
MsgBox MyPath & " doesn't exist"
Exit Sub
End If

FSO.deletefolder MyPath

Set FSO = Nothing
MyPath = Empty

End Sub
 



hi,

Can YOU go to that folder and DELETE it manually?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 


I can run your code, deleting a folder on my C drive.

Are you certain that your path spec is correct?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
What about this ?
FSO.DeleteFolder MyPath, True

BTW, no open file in that folder at the time of the delete ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
No other files or folders open.

The path has been double checked.

I will try FSO.DeleteFolder MyPath, True. Perhaps True will make the difference.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top