// public override string ToString() // { // var sb = new StringBuilder(); // sb.AppendLine(">> DeleteByAttribute:"); // sb.AppendLine($" - target directory: {this._sourceDir}"); // sb.AppendLine($" - file mask: {this._mask}"); // sb.AppendLine($" - include sub directories: {this._recursive}"); // sb.AppendLine($" - file attribute: {_fileAttribute.ToString()}"); // return sb.ToString(); // } public override void Apply(FileInfo file, int index) { if ((file.Attributes & _fileAttribute) == _fileAttribute) { try { if (!_test) { Win32ApiWrapper.MoveToRecycleBin(file.FullName); } if (_verbose) { ConsoleLog.WriteInfo($">>File '{file.FullName}' has been moved to RecycleBin, attribute: {_fileAttribute.ToString()}"); } } catch (AggregateException aex) { ConsoleLog.WriteError($"Error while deleting '{file.FullName}': {aex.Message}"); } catch (IOException ex) { ConsoleLog.WriteError($"Error while deleting '{file.FullName}': {ex.Message}"); } } }
public override void Apply(FileInfo file, int index) { if (!_test) { var tempFileName = Path.GetFileName(file.FullName); if (!DateTime.TryParse(tempFileName.Substring(0, 10), out _datePattern)) { ConsoleLog.WriteWarning($">> Unable to get date pattern from: '{tempFileName}'"); return; } var tempDirName = Path.GetDirectoryName(file.FullName); var newName = Path.Combine(tempDirName, "_" + tempFileName); using (var image = new Bitmap(file.FullName)) { image.ModifyDateTaken(_datePattern); image.Save(newName); var newFile = new FileInfo(newName); newFile.CreationTime = _datePattern; newFile.LastAccessTime = _datePattern; newFile.LastWriteTime = _datePattern; } Win32ApiWrapper.MoveToRecycleBin(file.FullName); } if (_verbose) { ConsoleLog.WriteInfo($">> Image '{file.FullName}' has been updated, date taken now is: {_datePattern}"); } }
public override void Apply(FileInfo file, int index) { if ((file.Length / 1024) < _maxSize) { if (!_test) { Win32ApiWrapper.MoveToRecycleBin(file.FullName); } if (_verbose) { ConsoleLog.WriteInfo($">> File '{file.FullName}' has been moved to RecycleBin, size: {file.Length / 1024}KB"); } } }