Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

deltree in VB

Posted on 1998-02-10
8
Medium Priority
?
268 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

927 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