Directory.Delete method

B

Brian Cahill

Hi,

I am attempting to delete Profile folders from C:\Documents and
Settings\. I am receiving a Permission denied error when using the
Directory.Delete method. Here is my code. Is there any way around
this? I am a Local Administrator on the PC where I am running the
application. I have tried rebooting and I am not logged in as the user
I am trying to delete. The folder is not empty and contained both
hidden files and folders as well as read only folders. As part of my
troubleshooting, I disabled Read only and (unhided???) all the folders.
Thanks

Imports System
Imports System.IO

Public Class Test
Public Shared Sub Main()
' Specify the directories you want to manipulate.
Dim path As String = "c:\Documents and Settings\ctx1"

Try
'This operation will not be allowed because there are
subdirectories.
Directory.Delete(path, True)
Catch e As Exception
MsgBox(e.Message.ToString)
End Try
End Sub
End Class
 
B

Brian Cahill

When I attempt to uncheck Read Only on C:\Documents and
Settings\ctx1\Application Data, it keeps coming back. Any way for me
to set this programatically then delete the folder. I know you can set
attributes for files but what about for folders?
 
G

Guest

Yes, you can do this using the DirectoryInfo class the same as you would use
the FileInfo class.
 
B

Brian Cahill

Thanks for your help but setting the attributes and then deleting did
not work. Any other ideas?
 
K

Kevin Spencer

You can't do this through the file system, because that folder represents an
OS entity (a User Profile).

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 
K

Kevin Spencer

BTW, from what I've been reading, it can be done programmatically through
WMI. So, you ought to be able to do it in .Net by using the
System.Management namespace classes. How, I don't know.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top