[英]How to delete multiple folders on VB.net
I have a code here but it doesn't work.我这里有一个代码,但它不起作用。
Dim folderExists As Boolean
folderExists = My.Computer.FileSystem.DirectoryExists(Directory.GetCurrentDirectory())
If folderExists = True Then
Directory.Delete(folderExists & "\LOG", True)
Directory.Delete(folderExists & "\logfile", True)
MsgBox("Logs deleted", vbInformation)
Else
MsgBox("Logs doesn't exists!")
End If
I want to delete folders and all the files inside them.我想删除文件夹和其中的所有文件。
Try this:尝试这个:
Dim folder = Directory.GetCurrentDirectory()
Dim folderExists As Boolean = (My.Computer.FileSystem.DirectoryExists(folder &"\LOG") And My.Computer.FileSystem.DirectoryExists(folder &"\logfile"))
If folderExists Then
Directory.Delete(folder & "\LOG", True)
Directory.Delete(folder & "\logfile", True)
MsgBox("Logs deleted", vbInformation)
Else
MsgBox("Logs doesn't exists!")
End If
Update - The folderExists
now checks for both folders.更新-
folderExists
现在检查两个文件夹。 Credit to @David Wilson for pointing that out.感谢@David Wilson指出这一点。
As an update to the answer fron @farhamanam -作为对@farhamanam 答案的更新 -
Dim folder = Directory.GetCurrentDirectory()
Dim folderExists As Boolean = (My.Computer.FileSystem.DirectoryExists(folder &"\LOG") and My.Computer.FileSystem.DirectoryExists(folder &"\logfile"))
If folderExists Then
Directory.Delete(folder & "\LOG", True)
Directory.Delete(folder & "\logfile", True)
MsgBox("Logs deleted", vbInformation)
Else
MsgBox("Logs don't exist!")
End If
If this works, give @farham the answer vote - Farham, you might want to edit your code to include this如果可行,请给@farham 投票 - Farham,您可能需要编辑代码以包含此内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.