Remove directory contains read-only file

Hughng

Active member
Joined
Jun 24, 2003
Messages
42
How do I remove a directory that might contains read-only file. The Directory.delete() work fine if it only contains deletable files. But when a read-only file existed inside that directory, the function throw an exception. I am just wondering that any other command will delete the whole directory recursively.

I know that dos command "Rd /s /q xxxxx" will recursively remove the whole thing, but I could not call that in VB.NET for some reason.

Thank you for your help,


HN
 
You have to go through every file and set the attributes so its not ReadOnly.
This will do it for you:
Code:
Dim f As IO.FileInfo
Dim dir As New IO.DirectoryInfo("path to the directory")
For Each f In dir.GetFiles
   f.Attributes = IO.FileAttributes.Normal
Next
 

Similar threads

A
Replies
0
Views
159
AzAssociate.Samuel
A
A
Replies
0
Views
135
Alastair MacFarlane (UK)
A
S
Replies
0
Views
106
Stan Huang at Taiwan
S
D
Replies
0
Views
173
David William Smith
D
Back
Top