Example #1
0
        public void DeleteFolder(string path)
        {
            logger.Info("Attempting to send '{0}' to recycling bin", path);
            var recyclingBin = _configService.RecycleBin;

            if (String.IsNullOrWhiteSpace(recyclingBin))
            {
                logger.Info("Recycling Bin has not been configured, deleting permanently.");
                _diskProvider.DeleteFolder(path, true);
                logger.Debug("Folder has been permanently deleted: {0}", path);
            }

            else
            {
                var destination = Path.Combine(recyclingBin, new DirectoryInfo(path).Name);

                logger.Debug("Moving '{0}' to '{1}'", path, destination);
                _diskProvider.MoveFolder(path, destination);

                logger.Debug("Setting last accessed: {0}", path);
                _diskProvider.FolderSetLastWriteTimeUtc(destination, DateTime.UtcNow);
                foreach (var file in _diskProvider.GetFiles(destination, SearchOption.AllDirectories))
                {
                    _diskProvider.FileSetLastWriteTimeUtc(file, DateTime.UtcNow);
                }

                logger.Debug("Folder has been moved to the recycling bin: {0}", destination);
            }
        }