Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Deleting folder does not work

  Asked By: Rani    Date: Nov 25    Category: MS Office    Views: 800
  

I want to delete a specific folder on the C drive (but not when running the
macro on a network), using the following code:
If FObject.GetDrive(FObject.GetDriveName(ELP)) = "C:" And Dir(WIP) <> ""
Then
FObject.DeleteFolder WIP, True
End If

Dir confirms that the folder is present, but DeleteFolder gives me error 76
(Path not found). When removing the path seperator by adding the code
WIP = Left(WIP, Len(WIP) - 1)
before the DelteFolder command, the error changes to 70 (permission denied.

ELP = the Excel Library Path which I use to determine if the macro is running on
c drive or a network.
WIP = "C:\windows\temp\~wqn\" which is directory containing different files,
including read-only files and being created during a file install process. It
has to be removed after installation is complete. I have to add that none of the
file in WIP is open by any application or running.

Does anybody has an idea what the problem is, and wy deleting the entire folder
doesn't work?

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Benjamin Simpson     Answered On: Nov 25

It's probably best to back off your final solution and do a little testing
first. The FSO FolderDelete method takes no prisoners and will err out
gracefully if there's an issue. So let's see if a couple tests with the
FSO method's for handling Exists and Delete:
So let's run it locally first and let's change the structure to a single
subroutine just to make sure all is working as we expect:
'===================================================
Set fso = CreateObject("Scripting.FileSystemObject")

WIP = "C:\windows\temp\~wqn\"
If (fso.FolderExists(WIP)) Then
fso.DeleteFolder(WIP, TRUE)
If Err <> 0 Then
msg=Err.Number & ", " & _
Err.Description & ": " & WIP
Err.Clear
Else
msg="Folder " & WIP & " deleted."
End If
Else
msg = fldr & " doesn't exist."
End If
'Check the Immediate window for the result
Debug.Print = msg
'===================================================

 
Didn't find what you were looking for? Find more on Deleting folder does not work Or get search suggestion and latest updates.




Tagged: