コード例 #1
0
        public static void MoveToTrash(ICollection <FileSystemInfo> collection)
        {
            try
            {
                if (collection.Count == 0 && collection == null)
                {
                    throw new Exception("Attempted to delete the same file  twice");
                }

                foreach (var fi in collection)
                {
                    if (collection.Count(e => e == fi) != 1)
                    {
                        throw new Exception("Attempted to delete the same file  twice");
                    }
                }

                foreach (var fi in collection)
                {
                    if (ShellUtilities.SendToRecycle(fi.FullName, ShellUtilities.FileOperationFlags.FOF_WANTNUKEWARNING) == false)
                    {
                        throw new Exception("Unhandled error");
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.Message == "Unhandled error")
                {
                    RecycleBin.Restore(collection);
                }
            }
        }
コード例 #2
0
 public void GetBack()
 {
     RecycleBin.Restore(RestoreCollection);
 }