Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

system.io.Directory

Status
Not open for further replies.

vttech

Technical User
Jan 28, 2006
297
US
I am using System.IO.Directory.Delete(FilePath)

I get the the folding error

The Directory is not empty

How can I delete a directory that is not empty in vb.net 2005


Code:
For Each SelectedItem As String In lbxComputerNames.SelectedItems

           

            Dim FilePath As String
            Dim UserName As String

            UserName = txtUserProfile.Text.Trim

            FilePath = lbxComputerNames.SelectedItem.ToString & "\c$\Documents and Settings\" & UserName

            If System.IO.Directory.Exists(FilePath) Then
                System.IO.Directory.Delete(FilePath)
                MessageBox.Show(txtUserProfile.Text & " profile was deleted from " & UserName)
            Else
                MessageBox.Show(txtUserProfile.Text & " profile does not exists on " & UserName)
            End If
Next

Newbie in search of knowledge
 
I tried the various ways to delete a file and directory below but because of permission issues it does not work. When I do it manually by start run and the unc path and right click to delete a directory, I get a dialog confirm File Delete if I select yes for each time that windows pops up I can delete the directory.. This rules out permission issue, I need to simulate this response via my code.
Any ideas or thoughts or ideas?



Code:
For Each strFile As String In IO.Directory.GetFiles(FilePath)
                    IO.File.Delete(strFile)
Next strFile


System.IO.Directory.Delete(FilePath, True)


Dim Dir As New System.IO.DirectoryInfo(FilePath)

'Delete the FilePath volume, including all files & subdirs
Dir.Delete(True)

Newbie in search of knowledge
 
it looks like what I need but I can't make heads or tails of it.

Newbie in search of knowledge
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top