Urgent assistance?

O

Omega Warrior

Problem with the following code:


Public Sub RecursiveDeleteDirectory( _

ByVal AsDirectoryName As String, _

ByVal AbDeleteSubDirectories As Boolean, _

ByVal AbDeleteFolders As Boolean)

' If we should delete our subdirectories too,

' browse first through all our subdirectories

If AbDeleteSubDirectories Then

Dim m_sSubdirectoryName As String

'Browse through the subdirectories

For Each m_sSubdirectoryName In _

System.IO.Directory.GetDirectories(AsDirectoryName)

'Delete everything in the current subdirectory

'by calling this function recursively

RecursiveDeleteDirectory _

(m_sSubdirectoryName, _

AbDeleteSubDirectories, _

AbDeleteFolders)

'Check if we need to delete the empty folders

If AbDeleteFolders Then

System.IO.Directory.Delete(m_sSubdirectoryName)

End If

Next

End If

'After we browsed through all the subdirectories

'we can delete all the files in this directory

Dim m_sFileName As String

'Browse through each file in the directory and delete it

For Each m_sFileName In _

System.IO.Directory.GetFiles(AsDirectoryName)

System.IO.File.Delete(m_sFileName) 'When the error shows this line of
code
is marked green

Next

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

RecursiveDeleteDirectory("C:\SVINJA", True, False)

End Sub

End Class





When i execute this i get the following error message:





An unhandled exception of type 'System.UnauthorizedAccessException'
occurred
in mscorlib.dll

Additional information: Access to the path "C:\SVINJA\SET3.tmp" is denied.



And the access is urely allowed, and i'm the administrator!

Please assist!



Thank You!
 
A

Andrej Tozon

Hi,
I guess the directory is simply acting its name... ;)
Are you sure the file isn't locked by another process? Can you delete it
with Windows Explorer? And this is probably a winforms app?

Andrej
 

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