Solved

deltree in VB

Posted on 1998-02-10
8
256 Views
Last Modified: 2010-05-18
Is there a way to simulate a DELTREE in VB.  Note that i'm using VB5 pro.
0
Comment
Question by:elecman
  • 3
  • 3
  • 2
8 Comments
 
LVL 8

Accepted Solution

by:
mrmick earned 100 total points
ID: 1456858
Set strPath to the path you wish to delete.  For example,

strPath = "Q:\TreeToDelete"
Shell "Command.com /c DelTree " & strPath

0
 
LVL 6

Expert Comment

by:anthonyc
ID: 1456859
This is a good answer for Win311 and Win95, but probably won't work in WinNT.  WinNT does not support all DOS features.

public Sub DelTree(strDir As String)
    Dim strCurrent As String
    Dim strFile()  As String
    Dim intI       As Integer
   
    strCurrent = Dir(strDir & "*.*", vbDirectory)
    ReDim strFile(0 To 0) As String
   
    Do Until Len(strCurrent) = 0
        Select Case strCurrent
        Case ".", ".."
            'do nothing
        Case Else
            If GetAttr(strDir & strCurrent) And vbDirectory Then
                ReDim Preserve strFile(0 To UBound(strFile) + 1) As String
                strFile(UBound(strFile)) = strDir & strCurrent & "\"
            Else
                If GetAttr(strDir & strCurrent) And vbReadOnly Then
                    SetAttr strDir & strCurrent, vbNormal
                End If
                Kill strDir & strCurrent
            End If
        End Select
       
        strCurrent = Dir()
    Loop
   
    For intI = 1 To UBound(strFile)
        DelTree strFile(intI)
    Next intI
   
    'kill dir
    RmDir strDir
End Sub

0
 

Author Comment

by:elecman
ID: 1456860
Use deltree in dos mode is too easy. I would like a true fonction in Visual Basic
0
 
LVL 8

Expert Comment

by:mrmick
ID: 1456861
Sorry elecman, there is no native function in VB equivalent to the DelTree.  Anthonyc provided you with a function that would basically do the same thing and I would have also had I understood what you wanted.

You can comment without grading - which will usually get you exactly what you want... or you can reject an answer and accept another instead when it is appropriate.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Expert Comment

by:anthonyc
ID: 1456862
elecman:

Mrmick gave a good answer, and gave code.  It works (not sure if it will in NT, it may, probably not on WinNT Server though).  I provided you with VB code.  It's slower, since it is not native, but it gets the job done.  You gave MrMick credit, which is fine.  Ify ou use my function, I would hope you provide a question for me to provide an answer to to get points.  If you don't, its ok.  I cant read the comments to this question any longer, since it costs me points to do so
0
 

Author Comment

by:elecman
ID: 1456863
I excuse for give 100 point to mrmick but is my first question.
But thnak for respond my answer
0
 
LVL 6

Expert Comment

by:anthonyc
ID: 1456864
its ok that you gave him to mr mick.  He provided a good answer.

If you want to reward me........ do this... make a new question.  Give it 100 points, call it "Reward for AnthonyC"  I will answer the question, and you can give me the grade you think I deserve.


0
 

Author Comment

by:elecman
ID: 1456865
ok
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now