using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.VisualBasic.FileIO; namespace RobvanderWoude { internal class Trash { static readonly string progver = "1.00"; static int Main( string[] args ) { UIOption dialogs = UIOption.OnlyErrorDialogs; if ( args.Length == 0 || args.Contains( "/?" ) ) { return ShowHelp( ); } foreach ( string arg in args ) { if ( arg.ToUpper( ) == "/V" ) { dialogs = UIOption.AllDialogs; } else if ( !File.Exists( arg ) ) { return ShowHelp( "File \"{0}\" not found", arg ); } } foreach ( string arg in args ) { if ( arg.ToUpper( ) != "/V" ) { try { FileSystem.DeleteFile( arg, dialogs, RecycleOption.SendToRecycleBin ); } catch ( Exception e ) { return ShowHelp( e.Message ); } } } return 0; } public static int ShowHelp( params string[] errmsg ) { #region Error Message if ( errmsg.Length > 0 ) { List errargs = new List( errmsg ); errargs.RemoveAt( 0 ); Console.Error.WriteLine( ); Console.ForegroundColor = ConsoleColor.Red; Console.Error.Write( "ERROR:\t" ); Console.ForegroundColor = ConsoleColor.White; Console.Error.WriteLine( errmsg[0], errargs.ToArray( ) ); Console.ResetColor( ); } #endregion Error Message #region Help Text /* Trash.exe, Version 1.00 Send specified file(s) to the recycle bin Usage: TRASH.EXE filespec [ filespec [ ... ] ] ] [ /V ] Where: filespec file to be sent to the recycle bin (no wildcards) /V Verbose output, show progress and error dialogs (default: error dialogs only) Written by Rob van der Woude https://www.robvanderwoude.com */ #endregion Help Text #region Display Help Text Console.Error.WriteLine( ); Console.Error.WriteLine( "Trash.exe, Version {0}", progver ); Console.Error.WriteLine( "Send specified file(s) to the recycle bin" ); Console.Error.WriteLine( ); Console.Error.Write( "Usage: " ); Console.ForegroundColor = ConsoleColor.White; Console.Error.WriteLine( "TRASH.EXE filespec [ filespec [ ... ] ] ] [ /V ]" ); Console.ResetColor( ); Console.Error.WriteLine( ); Console.Error.Write( "Where: " ); Console.ForegroundColor = ConsoleColor.White; Console.Error.Write( "filespec" ); Console.ResetColor( ); Console.Error.WriteLine( " file to be sent to the recycle bin (no wildcards)" ); Console.ForegroundColor = ConsoleColor.White; Console.Error.Write( " /V V" ); Console.ResetColor( ); Console.Error.WriteLine( "erbose output, show progress and error dialogs" ); Console.Error.WriteLine( " (default: error dialogs only)" ); Console.Error.WriteLine( ); Console.Error.WriteLine( "Written by Rob van der Woude" ); Console.Error.WriteLine( "https://www.robvanderwoude.com" ); #endregion Display Help Text return -1; } } }