You have not mentioned if this is a web application or a windows app.
Further, I don't see why you are creating a DirectoryInfo object when
all you need is the name (which is already present in the foundDir
variable).
That aside, it is almost certainly a permissions issue so (as
Velsankar said) you should check the ACL's for the given directory.
On Nov 25, 3:14 am, Pieter Hordijk <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I hope someone can help me with this cause I don't have any idea what
> is happening... :)
>
> When I run following code I get the following exception "Access to the
> path 'file.txt' is denied."
>
> While I am trying to get all directories in 'dir' and not files (or
> don't I?).
>
> Try
> For Each foundDir As String In
> My.Computer.FileSystem.GetDirectories(dir)
>
> Dim DirProps As DirectoryInfo = New DirectoryInfo(dir)
>
> If DirProps.Name.Contains("temp") Then
> My.Computer.FileSystem.DeleteDirectory(foundDir,
> FileIO.DeleteDirectoryOption.DeleteAllContents)
> End If
> Next
> Catch ex As Exception
> MsgBox(ex.Message)
> End Try
>
> What I am trying to do is check if 'temp' is in directory name and
> delete the directory if it is.
>
> Can someone help me with this one.
>
> Tnx