如何删除文件夹?在VB.Net中

时间:2016-01-22 07:14:56

标签: vb.net

''我创建了一个这样的文件夹,它包含许多数据库。当我即将再次提交按钮时,出现错误“#34;数据库已存在"我说我要删除src文件夹而不是数据库。那我该怎么办?使用什么代码?

Dim testPath1 As String = Form1.Dir_folder.Text & "\DDC OS" & "\CARD DECK" & "\" & DateTime.Now.ToString("yyyyMMdd") & "\" & batchFolderName & "\Compare"
Dim testPath5 As String = Form1.Dir_folder.Text & "\DDC OS" & "\CARD DECK" & "\" & DateTime.Now.ToString("yyyyMMdd") & "\" & batchFolderName & "\Entry1"
Dim testPath2 As String = Form1.Dir_folder.Text & "\DDC OS" & "\CARD DECK" & "\" & DateTime.Now.ToString("yyyyMMdd") & "\" & batchFolderName & "\Entry2"
Dim testPath3 As String = Form1.Dir_folder.Text & "\DDC OS" & "\CARD DECK" & "\" & DateTime.Now.ToString("yyyyMMdd") & "\" & batchFolderName & "\Images"
Dim testPath4 As String = Form1.Dir_folder.Text & "\CBATCH"
Dim testPath6 As String = Form1.Dir_folder.Text & "\CBATCH" & "\CardDeck" & "\" & DateTime.Now.ToString("yyyyMMdd")

If Not IO.Directory.Exists(testPath5) Then
    MkDir(testPath5)
End If
If Not IO.Directory.Exists(testPath1) Then
    MkDir(testPath1)
End If
If Not IO.Directory.Exists(testPath2) Then
    MkDir(testPath2)
End If
If Not IO.Directory.Exists(testPath3) Then
    MkDir(testPath3)
End If
If Not IO.Directory.Exists(testPath4) Then
    MkDir(testPath4)
End If
If Not IO.Directory.Exists(testPath6) Then
    MkDir(testPath6)
End If

2 个答案:

答案 0 :(得分:0)

说实话,MkDir不是创建目录的最快方法,但为了保持一致,只需使用

RmDir(testPath1)

更好的表现方式是使用..

My.Computer.FileSystem.CreateDirectory(testPath1)

创建目录和..

My.Computer.FileSystem.DeleteDirectory(testPath1,FileIO.DeleteDirectoryOption.DeleteAllContents)

删除它/

答案 1 :(得分:0)

你不能。我的回答与使用数据库无关。这就是为什么我因误读你原来的问题而道歉的原因。我应该删除它,让其他人回答。