我这里有代码,但它不起作用。
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
我想删除文件夹及其中的所有文件。
答案 0 :(得分:1)
试试这个:
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
更新 - folderExists
现在会检查这两个文件夹。感谢 @David Wilson 指出这一点。
答案 1 :(得分:1)
作为对@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
如果有效,请给@farham回答投票 - Farham,您可能需要编辑代码以包含此