Trouble deleteing folder

M

Mike

I am using vb.net, visual studio 2005 and running XP as an admin. My code
works fine for all but two folders in the parent folder. It deletes the
files and all other folders. There are 2 that will not delete. All have the
same attributes that I can see. I know I am missing something but I can't
find it. I have looked for hidden files but there aren't any. Any thing
else I can consider?

Thanks
Mike

Relevant code:
ClearFolder(di)
Directory.Delete(strPathToRead & strFolderPath, True) <--- Error on this line



Error I get:
Access to the path 'D:\My Plates\Only3folders_13\0034573' is denied.

Private Sub ClearFolder(ByVal di As DirectoryInfo)
Dim subdi As DirectoryInfo() = di.GetDirectories()
Dim f As FileInfo

For Each d As DirectoryInfo In subdi
Dim fi As FileInfo() = d.GetFiles()
For Each f In fi
f.Attributes = FileAttributes.Normal
f.Delete()
Next
ClearFolder(d)
Next
End Sub
 
M

Mike

So now I have this work around. How do I perform the task without the users
seeing the window open and close?

Dim strPath As String = "D:\My Plates\Only3folders_13\020009-AC"

'attrib -r drive:\<path>\<foldername>

Dim program As New Process()
program.StartInfo.FileName = "C:\windows\system32\attrib.exe"
program.StartInfo.Arguments = "+r " & Chr(34) & strPath & Chr(34)

program.Start()
 
J

joecool1969

So now I have this work around.  How do I perform the task without the users
seeing the window open and close?

Dim strPath As String = "D:\My Plates\Only3folders_13\020009-AC"

        'attrib -r drive:\<path>\<foldername>

        Dim program As New Process()
        program.StartInfo.FileName = "C:\windows\system32\attrib.exe"
        program.StartInfo.Arguments = "+r " & Chr(34) & strPath& Chr(34)

        program.Start()

Did you try

program.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
 
M

Mike

That was what I was missing. I guess I should explore these methods better.
Turns out I also needed

program.WaitForExit()

Thanks for your help
 

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