Exemple #1
0
        static void Rotate(Parameters parameters, RotationInfo ri)
        {
            string destination;

            foreach (var(number, filepath) in Enumerate(ri).OrderByDescending(x => x.number))
            {
                if (number == parameters.FileCount)
                {
                    Logger.Info($"Deleting: '{filepath}'");

                    File.Delete(filepath);

                    Logger.Info("Deleted");
                }
                else
                {
                    destination = $"{ri.Directory}{Path.DirectorySeparatorChar}{ri.Name}.{number + 1}.{ri.Extension}";

                    Logger.Info($"Moving: '{filepath}' => '{destination}'");

                    File.Move(filepath, destination);

                    Logger.Info("Moved");
                }
            }

            destination = $"{ri.Directory}{Path.DirectorySeparatorChar}{ri.Name}.2.{ri.Extension}";

            Logger.Info($"Moving: '{ri.FullPath}' => '{destination}'");

            File.Move(ri.FullPath, destination);

            Logger.Info("Moved");
        }
Exemple #2
0
        static IEnumerable <(int number, string filepath)> Enumerate(RotationInfo ri)
        {
            string number;

            foreach (var filepath in Directory.EnumerateFiles(ri.Directory, $"{ri.Name}.*.{ri.Extension}"))
            {
                //
                // On Windows, Directory.EnumerateFiles returns all paths in lower case
                // regardless of their actual case.
                //
                number = filepath.ToLower()
                         .Replace(ri.Directory.ToLower() + Path.DirectorySeparatorChar, "")
                         .Replace(ri.Name.ToLower() + '.', "")
                         .Replace('.' + ri.Extension.ToLower(), "");

                yield return(int.Parse(number), filepath);
            }
        }