Vb.net 从路径中获取文件夹名称
有一个名为temp的目录。它包含不同名称的各种文件夹。我想删除特定名称的文件夹,如test。如何在Vb.net 从路径中获取文件夹名称,vb.net,path,directory,Vb.net,Path,Directory,有一个名为temp的目录。它包含不同名称的各种文件夹。我想删除特定名称的文件夹,如test。如何在vb.net中删除它。请帮助我。确保导入系统.IO 那你就可以这么做了 File.Delete(path) 其中path是一个等于路径值的字符串。请小心使用以下代码,并根据需要编辑代码: Imports System.IO Public Class Form1 Private Sub btnDelete_Click(sender As Object, e As EventArgs) Hand
vb.net
中删除它。请帮助我。确保导入系统.IO
那你就可以这么做了
File.Delete(path)
其中path是一个等于路径值的字符串。请小心使用以下代码,并根据需要编辑代码:
Imports System.IO
Public Class Form1
Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
Dim directoryName As String = "D:\_working"
Dim subPath = directoryName & "\TEST" '// be careful - subPath will be deleted!
Try
Dim directoryExists = Directory.Exists("D:\_working")
Dim subDirectoryExists = Directory.Exists(subPath)
MessageBox.Show("top-level directory exists: " & directoryExists)
MessageBox.Show("sub-directory exists: " & subDirectoryExists)
For Each deleteFile In Directory.GetFiles(subPath, "*.BMP", SearchOption.TopDirectoryOnly)
File.Delete(deleteFile)
'// you may want to log all deleted files here ...
Next
Directory.Delete(subPath) '// without the need of logging add ..(subPath, true)
Catch ex As Exception
MessageBox.Show("The process failed: {0}", ex.Message)
End Try
End Sub
End Class
欢迎来到堆栈溢出!这个网站不是一个代码编写服务(你只是偶尔运气好)。请浏览、和部分,了解此网站的工作原理,并帮助您改进当前和未来的问题,这可以帮助您获得更好的答案。而不是重复您可以调用的每个文件。