Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitlePermanently delete files dragged onto this program
Keywordskill, delete, remove, files, command-line parameters, drag and drop
CategoriesFiles and Directories, Software Engineering, Utilities
 
This program starts with Sub Main and has no forms.

When you drag files from Windows Explorer onto the program, Windows runs the program passing it the names of the files as command-line arguments separated by spaces. Compile this program and place a shortcut to the executable on your desktop, in a folder, or some other place so you can conveniently drag and drop files onto it. Add a shortcut to Windows/SendTo to make it appear in the SendTo popup menu.

The program uses Split to separate the file names, verifies that there is at least one file, and asks the user to verify the deletion. It then loops through the file names using VB's Kill statement to delete them.

This is much faster than moving the files into the wastebasket and you don't need to empty the wastebasket later, a step that is also relatively slow. The downside is files removed in this way are immediately lost forever.

 
Private Sub Main()
Dim file_names As Variant
Dim i As Integer

    file_names = Split(Command$, " ")
    If UBound(file_names) < LBound(file_names) Then
        MsgBox "Do not start this program interactively." & _
            _
            vbCrLf & vbCrLf & _
            "Instead, drag and drop files onto the " & _
                "program's icon to permanently delete the " & _
                "files.", _
            vbInformation
    Else
        If MsgBox("Permanently delete these " & _
            UBound(file_names) - LBound(file_names) + 1 & _
            " files?", vbQuestion Or vbYesNo) = vbYes _
        Then
            On Error Resume Next
            For i = LBound(file_names) To UBound(file_names)
                Kill file_names(i)
                If Err.Number <> 0 Then
                    MsgBox "Error killing file " & _
                        file_names(i) & _
                        vbCrLf & Err.Description
                End If
            Next i
        End If
    End If
End Sub
 
Note that Windows 98 has trouble sending many files to an application. If you drag more than about a dozen files onto the program, the system displays the message "Access to the specified device, path, or file is denied."

If you find a workaround, let me know.

 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated