Solved

deltree in VB

Posted on 1998-02-10
8
255 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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.
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 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…

757 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

22 Experts available now in Live!

Get 1:1 Help Now