小编给大家分享一下VB.NET如何删除文件夹,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
VB.NET删除文件夹代码:
Option Explicit Private Sub Command1_Click() Dim strPathName As String strPathName = "" strPathName = InputBox("请输入需要删除的文件夹名称∶", "删除文件夹") If strPathName = "" Then Exit Sub On Error GoTo ErrorHandle SetAttr strPathName, vbNormal '此行主要是为了检查文件夹名称的有效性 RecurseTree strPathName Label1.Caption = "文件夹" & strPathName & "已经删除!" Exit Sub ErrorHandle: MsgBox "无效的文件夹名称:" & strPathName End Sub Sub RecurseTree(CurrPath As String) Dim sFileName As String Dim newPath As String Dim sPath As String Static oldPath As String sPath = CurrPath & "\" sFileName = Dir(sPath, 31) '31的含义∶31=vbNormal+vbReadOnly+vbHidden+vbSystem+vbVolume+vbDirectory Do While sFileName <> "" If sFileName <> "." And sFileName <> ".." Then If GetAttr(sPath & sFileName) And vbDirectory Then '如果是目录和文件夹 newPath = sPath & sFileName RecurseTree newPath sFileName = Dir(sPath, 31) Else SetAttr sPath & sFileName, vbNormal Kill (sPath & sFileName) Label1.Caption = sPath & sFileName '显示删除过程 sFileName = Dir End If Else sFileName = Dir End If DoEvents Loop SetAttr CurrPath, vbNormal RmDir CurrPath Label1.Caption = CurrPath End Sub
以上是“VB.NET如何删除文件夹”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。