Projects

Find all our projects in development below.
All source code is GNU General Public License (GPL)

SendToRecycleBin

Browsing modMain.vb (2.85 KB)

Option Explicit On

Imports System.IO

Module modMain

    Sub Main()

        ' enumerate the command line arguments
        For Each thisCmd As String In My.Application.CommandLineArgs

            If File.Exists(thisCmd) Then

                Try

                    ' delete the specified file
                    My.Computer.FileSystem.DeleteFile(thisCmd, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin)

                    Console.WriteLine("Deleted file: " + thisCmd)

                Catch ex As Exception

                    Console.WriteLine("Error deleting file: " + thisCmd + " (" + ex.Message + ")")

                End Try

            ElseIf Directory.Exists(thisCmd) Then

                If thisCmd.EndsWith("\") Then _
                    thisCmd.Substring(0, thisCmd.Length - 1)

                Try

                    ' delete the specified directory
                    My.Computer.FileSystem.DeleteDirectory(thisCmd, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin)

                    Console.WriteLine("Deleted directory: " + thisCmd)

                Catch ex As Exception

                    Console.WriteLine("Error deleting directory: " + thisCmd + " (" + ex.Message + ")")

                End Try

            ElseIf thisCmd.Contains("\") And thisCmd.Contains("*") Then

                Dim path As String = thisCmd.Substring(0, thisCmd.LastIndexOf("\"))
                Dim pattern As String = thisCmd.Substring(thisCmd.LastIndexOf("\") + 1)

                Dim files() As String = Directory.GetFiles(path, pattern)

                If files.GetUpperBound(0) > 0 Then

                    For Each thisFile As String In files

                        Try

                            ' delete the specified file
                            My.Computer.FileSystem.DeleteFile(thisFile, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.SendToRecycleBin)

                            Console.WriteLine("Deleted file: " + thisFile)

                        Catch ex As Exception

                            Console.WriteLine("Error deleting file: " + thisFile + " (" + ex.Message + ")")

                        End Try

                    Next

                End If

            End If

        Next ' thisCmd

        If My.Application.CommandLineArgs.Count = 0 Or _
            (My.Application.CommandLineArgs.Count > 0 AndAlso _
            My.Application.CommandLineArgs.Item(0) = "/?") Then

            Console.WriteLine("Send Files/Folders to Recycle Bin" + vbCrLf)
            Console.WriteLine("Usage: sendtorecyclebin [file path]")
            Console.WriteLine("Usage: sendtorecyclebin [folder path]")
            Console.WriteLine("Usage: sendtorecyclebin [folder path\wildcard]")

        End If

    End Sub

End Module

Download modMain.vb

Back to file list


Back to project page