Solved

deltree in VB

Posted on 1998-02-10
8
261 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

821 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