using System; using System.Collections.Generic; using System.Text; using System.IO; namespace sharpreleaser { public class DeleteCommand : Command { private bool recursive; public bool Recursive { get { return recursive; } set { recursive = value; } } public DeleteCommand() : base(CommandType.DELETE, string.Empty) { } public override void Execute(Project project) { string path = project.ParseVariables(CommandText); try { FileAttributes attributes = File.GetAttributes(path); if ((attributes & FileAttributes.Directory) > 0) { DirectoryInfo info = new DirectoryInfo(path); info.Delete(Recursive); } else { FileInfo info = new FileInfo(path); info.Delete(); } Output = "Deleted: " + path; } catch (FileNotFoundException) { Output = "File not found: " + path; } catch (Exception ex) { Error = ex.ToString(); } } } }