用VB.NET 删除文件夹 连带这子目录一起删除怎么处理
展开全部
看看这个,有删除的
Public strPath As String '要导出的文件夹路径
Public NewFile As String '文件保存用
'创建文件夹
Public Sub CreatemyFolder(str As String)
Dim Mybook As Workbook
Dim f
Dim mypath As String
'Dim NewFile As String
Dim strPathFolder$
Dim abc As Object
NewFile = str
'强制覆盖保存时,不让确认框弹出?
Application.DisplayAlerts = False
Set Mybook = ThisWorkbook '把当前工作簿定义为变量Mybook
mypath = ThisWorkbook.Path & "\"
strPathFolder = mypath & NewFile
strPath = strPathFolder & "\"
On Error Resume Next
Set abc = CreateObject("Scripting.FileSystemObject")
If abc.FolderExists(strPathFolder) = True Then
'===删除文件夹==========
Set f = abc.GetFolder(strPathFolder)
f.Delete
abc.CreateFolder (strPathFolder)
'===删除文件夹==========
Exit Sub
Else
abc.CreateFolder (strPathFolder)
End If
Set abc = Nothing
End Sub
Public strPath As String '要导出的文件夹路径
Public NewFile As String '文件保存用
'创建文件夹
Public Sub CreatemyFolder(str As String)
Dim Mybook As Workbook
Dim f
Dim mypath As String
'Dim NewFile As String
Dim strPathFolder$
Dim abc As Object
NewFile = str
'强制覆盖保存时,不让确认框弹出?
Application.DisplayAlerts = False
Set Mybook = ThisWorkbook '把当前工作簿定义为变量Mybook
mypath = ThisWorkbook.Path & "\"
strPathFolder = mypath & NewFile
strPath = strPathFolder & "\"
On Error Resume Next
Set abc = CreateObject("Scripting.FileSystemObject")
If abc.FolderExists(strPathFolder) = True Then
'===删除文件夹==========
Set f = abc.GetFolder(strPathFolder)
f.Delete
abc.CreateFolder (strPathFolder)
'===删除文件夹==========
Exit Sub
Else
abc.CreateFolder (strPathFolder)
End If
Set abc = Nothing
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
抄一段:
Try
My.Computer.FileSystem.DeleteDirectory("D:\1", FileIO.DeleteDirectoryOption.ThrowIfDirectoryNonEmpty)
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
Try
My.Computer.FileSystem.DeleteDirectory("D:\1", FileIO.DeleteDirectoryOption.ThrowIfDirectoryNonEmpty)
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
追问
这个只能删除空目录
追答
Try
My.Computer.FileSystem.DeleteDirectory("D:\1", FileIO.DeleteDirectoryOption.DeleteAllContents)
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
把删除属性修改下就可以全部删除: ThrowIfDirectoryNonEmpty 改为 DeleteAllContents,这样很方便
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询