Solved

Delete Folder in Directory List

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Batch file output 20 77
for loop with Set 4 45
Arduino EDI - Programming language 3 61
Programatically extract date from website 8 0
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…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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 …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

706 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

21 Experts available now in Live!

Get 1:1 Help Now