Solved

deltree in VB

Posted on 1998-02-10
8
266 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 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…
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…
Suggested Courses
Course of the Month11 days, 12 hours left to enroll

623 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