public Dictionary <string, string> Compose(ComposeInstructions input) { instructions = input; textToReplace = instructions.TextToReplace; customText = instructions.CustomText; if (TextToReplaceIsNotFoundInAnyFileName()) { return(ErrorMessage("Custom text to replace not found in any filename.")); } foreach (var file in instructions.Files) { GetTempFileInfo(file); if (tempFile.Path.Contains(textToReplace)) { ComposeBaseName(); } if (Composition.Any()) { HandleDuplicates(); } } return(Composition); }
public Dictionary <string, string> Compose(ComposeInstructions input) { instructions = input; instructions.Files.Sort(delegate(FileInformation first, FileInformation second) { return(first.CreationDateTime.CompareTo(second.CreationDateTime)); }); foreach (var file in instructions.Files) { GetTempFileInfo(file); ComposeBaseName(); if (Composition.Any()) { HandleDuplicates(); } Composition.Add(tempFile.Path, GetNewPath()); } return(Composition); }
public Dictionary <string, string> Compose(ComposeInstructions instructions) { int duplicateCounter = 1; foreach (var file in instructions.Files) { var path = file.Path; var directory = Path.GetDirectoryName(path); var extension = Path.GetExtension(path); string dateFormat; if (instructions.Mode == ComposeMode.Date) { dateFormat = "yyyyMMdd"; } else { dateFormat = "yyyyMMdd_HHmmss"; } var creationDate = file.CreationDateTime.ToString(dateFormat); if (Composition.Any()) { if (Composition.Values.Last().EndsWith($"{creationDate}{extension}")) { string lastKey = Composition.Keys.Last(); Composition.Remove(lastKey); Composition.Add(lastKey, $"{directory}{Separator}{creationDate}_({duplicateCounter}){extension}"); duplicateCounter++; creationDate += $"_({duplicateCounter})"; duplicateCounter++; } else if (Composition.Values.Last().Contains(creationDate)) { creationDate += $"_({duplicateCounter})"; duplicateCounter++; } else { duplicateCounter = 1; } } string newPath = $"{directory}{Separator}{creationDate}{extension}"; Composition.Add(path, newPath); } return(Composition); }
public Dictionary <string, string> Compose(ComposeInstructions input) { instructions = input; customText = instructions.CustomText; foreach (var file in instructions.Files) { GetTempFileInfo(file); ComposeBaseName(); if (Composition.Any()) { HandleDuplicates(); } Composition.Add(file.Path, GetNewPath()); } return(Composition); }