public Dictionary <string, string> Compose(ComposeInstructions instructions)
        {
            string truncationText = instructions.CustomText;

            if (!instructions.Files.Any(x => x.Path.Contains(truncationText)))
            {
                return(ErrorMessage("Custom text to truncate not found in any filename."));
            }

            foreach (var file in instructions.Files)
            {
                string path    = file.Path;
                string newPath = string.Empty;

                if (Path.GetFileName(path).Contains(truncationText))
                {
                    string directory = Path.GetDirectoryName(path);
                    var    extension = Path.GetExtension(path);

                    int index = path.IndexOf(truncationText);
                    int count = truncationText.Length;
                    newPath = path.Remove(index, count);
                }
                else
                {
                    continue;
                }

                Composition.Add(path, newPath);
            }

            return(Composition);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        public Dictionary <string, string> Compose(ComposeInstructions instructions)
        {
            string customText = instructions.CustomText;
            string directory  = Path.GetDirectoryName(instructions.Files[0].Path);

            int counter = 1;

            foreach (var file in instructions.Files)
            {
                string extension = Path.GetExtension(file.Path);
                string newPath   = $"{directory}{Separator}{customText}_({counter++}){extension}";
                Composition.Add(file.Path, newPath);
            }

            return(Composition);
        }
        public Dictionary <string, string> Compose(ComposeInstructions instructions)
        {
            foreach (var file in instructions.Files)
            {
                string newExtension = instructions.CustomText.Trim('.');

                string path    = file.Path;
                string newPath = Path.GetDirectoryName(path)
                                 + Separator
                                 + Path.GetFileNameWithoutExtension(path)
                                 + $".{newExtension}";

                Composition.Add(path, newPath);
            }

            return(Composition);
        }
Beispiel #7
0
        public Dictionary <string, string> Compose(ComposeInstructions instructions)
        {
            instructions.Files.Sort((x, y) => DateTime.Compare(x.CreationDateTime, y.CreationDateTime));

            for (int i = 0; i < instructions.Files.Count; i++)
            {
                var path      = instructions.Files[i].Path;
                var directory = Path.GetDirectoryName(path);
                var extension = Path.GetExtension(path);

                string newPath = $"{directory}{Separator}{i + 1}{extension}";

                Composition.Add(path, newPath);
            }

            return(Composition);
        }
Beispiel #8
0
        public Dictionary <string, string> Compose(ComposeInstructions input)
        {
            instructions = input;
            instructions.Files.Sort((x, y) => DateTime.Compare(x.CreationDateTime, y.CreationDateTime));

            foreach (var file in instructions.Files)
            {
                GetTempFileInfo(file);

                ComposeBaseName();
                string newPath = GetNewFileName();
                Composition.Add(tempFile.Path, newPath);

                counter++;
            }

            return(Composition);
        }
Beispiel #9
0
        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);
        }