Delete the folder of the tape folder in vb

Source: Internet
Author: User

Use recursive algorithms to delete directories with multi-level subdirectories
Option Explicit
Private Sub commandementclick ()
Dim strPathName As String
StrPathName = ""
StrPathName = InputBox ("enter the name of the folder to be deleted:", "delete folder ")
If strPathName = "" Then Exit Sub
On Error GoTo ErrorHandle
SetAttr strPathName, vbNormal this line is mainly used to check the validity of the folder name
RecurseTree strPathName
Label1.Caption = "folder" & strPathName & "deleted! "
Exit Sub
ErrorHandle:
MsgBox "invalid folder name:" & 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 meaning: 31 = vbNormal + vbReadOnly + vbHidden + vbSystem + vbVolume + vbDirectory
Do While sFileName <> ""
If sFileName <> "." And sFileName <> ".." Then
If GetAttr (sPath & sFileName) And vbDirectory Then 'is a directory And folder
NewPath = sPath & sFileName
RecurseTree newPath
SFileName = Dir (sPath, 31)
Else
SetAttr sPath & sFileName, vbNormal

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.