如何删除包含子目录和文本文件的子目录

时间:2015-05-11 20:09:02

标签: vb.net

我想删除一个子目录,该子目录包含另一个包含文本文件的子目录。我正在使用的代码是:

#myPlayerID.vjs-has-started.vjs-user-inactive .vjs-play-progress {
  height: 10px;
  transition-property: height;
  -transition-delay: 3s;
  -webkit-transition-delay: 3s; 
}

这对我不起作用。请问我该如何重写呢?我正在使用VB 2010 Express。提前谢谢。

2 个答案:

答案 0 :(得分:1)

不要使用File.Delete(path)使用Directory.Delete(path, true) true表示递归删除目录和子目录的内容。

答案 1 :(得分:1)

试试这个:

Dim Nb = New DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "Student List\" & TextBox10.Text))
    Try
        If Directory.Exists(Nb.FullName) Then
            Dim oDirectory As New DirectoryInfo(Nb.FullName)
            If oDirectory.GetFiles.Count > 0 Then
                For Each oFile As FileInfo In oDirectory.GetFiles
                    oFile.Delete()
                Next
            End If
            If oDirectory.GetDirectories.Count > 0 Then
                For Each oDir As DirectoryInfo In oDirectory.GetDirectories
                    oDir.Delete(True)
                Next
                Nb.Delete()
            End If
        End If
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
相关问题