[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

Delete Folder in Directory List

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
smithmrk
Asked:
smithmrk
1 Solution
 
brettmjohnsonCommented:
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
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
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
 
smithmrkAuthor Commented:
Excellent!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

You Rock!

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


Thanks,
smithmrk
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now