Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

IO.Directory.Delete - Read-only "Access Denied"

$
0
0
I'm in the middle of a major project converting a VB6 application to .NET and have a requirement to delete a folder and its contents, in this case a complete user profile folder from C:\Documents and Settings.

In VB6 I used the Scripting.FileSystemObject's DeleteFolder method successfully, however I'm unable to do so in .NET.

I'm using the following function:

Public Function DeleteFolder(ByVal strFolderName As String) As Boolean
   Try
       IO.Directory.Delete(strFolderName, True)
       Return True
   Catch ex As Exception
       Debug.Print(ex.Message)
       Return False
   End Try
End Function

Whenever I run this, I get an IOException "Access to the path '\\COMPUTERNAME\C$\Documents and Settings\USERNAME\Application Data\Microsoft\Internet Explorer\Quick Launch' is denied."

As usual, a (probably) very simple problem that's caused me several lost hours.

Is there a way to get this working, or can someone help me with a replacement routine that will recursively delete the folder's contents, taking care of permissions and read-only issues on-the-fly?

Thanks!

Viewing all articles
Browse latest Browse all 1710

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>