Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Experts*
Posted

You have to go through every file and set the attributes so its not ReadOnly.

This will do it for you:

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...