Solved

Delete Folder in Directory List

Posted on 2004-09-10
3
193 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

Technology Partners: 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

This article will show, step by step, how to integrate R code into a R Sweave document
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

732 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