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

如何删除文件夹?在VB.Net中,vb.net,Vb.net,“”我创建了一个这样的文件夹,其中包含许多数据库。当我准备再次提交按钮时,出现了一个错误“数据库已经存在”,我是说我要删除src文件夹而不是数据库。那我该怎么办?使用什么代码 Dim testPath1 As String = Form1.Dir_folder.Text & "\DDC OS" & "\CARD DECK" & "\" & DateTime.Now.ToString("yyyyMMdd") & "\" & batchFolderNa

“”我创建了一个这样的文件夹,其中包含许多数据库。当我准备再次提交按钮时,出现了一个错误“数据库已经存在”,我是说我要删除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

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

RmDir(testPath1)
更好的执行方式是使用

My.Computer.FileSystem.CreateDirectory(testPath1)
创建一个目录并

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

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

有关提示,请参阅。如果您没有设置格式并提出正确的问题,您的问题将被删除。因此,请按照@WaiHaLeeCould建议的链接,再详细说明一下“再次提交”的含义。是否再次单击同一按钮以创建相同的文件夹?请尝试以下操作:是。创建文件夹和删除文件夹位于同一按钮中。我正要删除它,但它已存在。但文件夹中的数据库似乎已被锁定。我将使用什么代码解锁它,以便删除文件夹?释放(解锁)数据库如何?这样我就可以用一个按钮立即删除文件夹了?好吧,你必须关闭所有打开的与要删除的数据库的连接。如果它们是使用您的程序打开的,那么应该很简单。如果连接被另一个程序打开,这更像是一个问题。我用connection.close()关闭了它,但仍然不工作。如何计算数据库中的行数?嗨,David,你能帮助我使用openfiledialog浏览mdb文件并通过datagridview工具更新其中的行数吗?