Solved

Delete Folder in Directory List

Posted on 2004-09-10
3
194 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
[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 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 86

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

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!

Question has a verified solution.

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

A short article about a problem I had getting the GPS LocationListener working.
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.
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…
Introduction to Processes

690 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