Solved

Delete Folder in Directory List

Posted on 2004-09-10
3
189 Views
Last Modified: 2010-04-17
Hello all!

I have a DirectoryList Box and when I press the Delete Key (#46) on the key board I want to delete the selected folder that is highlighted in the DirectoryList Box.

How can this be done?

Thanks,
smithmrk
0
Comment
Question by:smithmrk
3 Comments
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 12029463
You could let the system do it:

system("/bin/rm -rf /path/to/folder");

If you want to do it yourself, look into the rmdir() and unlink() system library calls
to recursively delete a directory and its contents:

man 2 rmdir
man 2 unlink


0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 12029892
You need to add a reference to the Microsoft Scripting Runtime for this to work:
    Project --> References, check "Microsoft Scripting Runtime"

Private Sub Form_Load()
    Me.KeyPreview = True
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Dim folderName As String
    If KeyCode = vbKeyDelete Then
        If Dir1.ListIndex <> -1 Then
            folderName = Dir1.List(Dir1.ListIndex)
        Else
            folderName = Dir1.Path
        End If
        If folderName <> "" Then
            deleteFolder folderName
        End If
    End If
End Sub

Private Sub deleteFolder(ByVal folderName As String)
    ' Project --> References, check "Microsoft Scripting Runtime"
    Dim fso As Scripting.FileSystemObject

    Set fso = New Scripting.FileSystemObject
    fso.GetFolder(folderName).Delete True
    Set fso = Nothing
End Sub
0
 

Author Comment

by:smithmrk
ID: 12030223
Excellent!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

You Rock!

That is Perfect!!!!!!!!!!!!!!!!!!!!


Thanks,
smithmrk
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

Suggested Solutions

Title # Comments Views Activity
how to open Waze.com/livemap from address saved in DB? 26 177
groupSumClump challenge 9 102
Help to convert powershell script into a gui 9 141
Recommendation vb6 to vb.net or others 14 112
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
This is about my first experience with programming Arduino.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

895 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

16 Experts available now in Live!

Get 1:1 Help Now