コード例 #1
0
        public void GetFilePathsWithoutSubfolders()
        {
            var paths = new string[]
            {
                @"tests\Kashmir.mp3",
                @"tests\Led Zeppelin - Kashmir.mp3",
                @"tests\Led Zeppelin - Stairway to Heaven.mp3"
            };

            var renamer       = new FileRenamer(directory);
            var recieverPaths = renamer.GetFilePaths(directory, "*.mp3", false);

            var expectedPaths = String.Empty;

            foreach (var path in paths)
            {
                expectedPaths += path;
            }

            var actualPaths = String.Empty;

            foreach (var path in recieverPaths)
            {
                actualPaths += path;
            }

            Assert.AreEqual(expectedPaths, actualPaths);
        }
コード例 #2
0
        private async void UpdateListViewAsync()
        {
            foreach (StorageFile file in files)
            {
                var tmpStream = await file.OpenStreamForReadAsync();

                var path     = file.Path;
                var name     = file.Name;
                var fileType = file.FileType;

                var newName = "";
                try
                {
                    newName = $"{FileRenamer.GetNewName(path, tmpStream)}{fileType}";

                    if (newName == name)
                    {
                        name    = $"✔ {name}";
                        newName = "Already renamed 💯";
                    }
                    else
                    {
                        name = $"⚙ {name}";
                    }
                }
                catch (Exception)
                {
                    name    = $"💥 {name}";
                    newName = "Can't find a new name ☹";
                }

                viewList.Add($"{name} ➡ {newName}");
            }
        }
コード例 #3
0
        private async void RenameButton_ClickAsync(object sender, RoutedEventArgs e)
        {
            foreach (StorageFile file in files)
            {
                var tmpStream = await file.OpenStreamForReadAsync();

                var newName = $"{FileRenamer.GetNewName(file.Path, tmpStream)}{file.FileType}";

                while (true)
                {
                    try
                    {
                        await file.RenameAsync(newName);

                        break;
                    }
                    catch
                    {
                        newName = $"extra_{newName}";
                        // TODO: Make this hack less disgusting.
                    }
                }
            }
            viewList.Clear();
        }
コード例 #4
0
        private void UpdateListView()
        {
            foreach (string file in files)
            {
                var name     = Path.GetFileName(file);
                var path     = Path.GetFullPath(file);
                var fileType = Path.GetExtension(file);

                var newName = "";
                try
                {
                    newName = $"{FileRenamer.GetNewName(path)}{fileType}";

                    if (newName == name)
                    {
                        name    = $"✔ {name}";
                        newName = "Already renamed 💯";
                    }
                    else
                    {
                        name = $"⚙ {name}";
                    }
                }
                catch (Exception)
                {
                    name    = $"💥 {name}";
                    newName = "Can't find a new name ☹";
                }

                viewList.Add($"{name} ➡ {newName}");
            }
        }
コード例 #5
0
        private async void RenameButton_ClickAsync(object sender, RoutedEventArgs e)
        {
            var renamer = new FileRenamer(new Mover());
            await Task.Run(() => renamer.RenameFiles(files.ToList()));

            viewList.Clear();
        }
コード例 #6
0
ファイル: LibraryTest.cs プロジェクト: taler0n/Students
        public void TimeMeasureRenamerWithNullFile()
        {
            FileRenamer            baseRenamer = new FileRenamer();
            FileRenamerTimeMeasure renamer     = new FileRenamerTimeMeasure(baseRenamer);

            renamer.Rename(null);
        }
コード例 #7
0
        private void Rename_Click(object sender, EventArgs e)
        {
            if (findTextBox.Text == "" || replaceTextBox.Text == "" || directoryTextBox.Text == "")
            {
                MessageBox.Show("Please make sure all text boxes are filled.");
            }
            else
            {
                if (Directory.Exists(directoryTextBox.Text))
                {
                    FileRenamer fileRenamer = new FileRenamer();

                    bool overwrite  = overwriteCheckBox.Enabled;
                    bool subfolders = subfoldersCheckBox.Enabled;
                    bool contents   = contentsCheckBox.Enabled;

                    fileRenamer.renameInitialization(directoryTextBox.Text, findTextBox.Text, replaceTextBox.Text, overwrite, contents, subfolders, false, false);
                }
                else
                {
                    MessageBox.Show("Please ensure the directory path is to an existing directory.");
                }

                MessageBox.Show("Rename Complete");
            }
        }
コード例 #8
0
        public void Setup()
        {
            this.file = MockRepository.GenerateStub<IFile>();
            this.converter = MockRepository.GeneratePartialMock<FileNameConverter>();

            this.fileRenamer = new FileRenamer(this.file, this.converter, testFileNames);
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: MonkeyHood/SimpleRenamer
        static void Main(string[] args)
        {
            FileMover   fileMover   = new FileMover();
            FileRenamer fileRenamer = new FileRenamer();

            fileMover.FlattenFolder();
            fileRenamer.CompressFileNumbers();
        }
コード例 #10
0
ファイル: LibraryTest.cs プロジェクト: taler0n/Students
        public void PermitionsCheckerRenamerWithNullFile()
        {
            FileRenamer baseRenamer = new FileRenamer();
            FileRenamerPermitionsChecker renamer =
                new FileRenamerPermitionsChecker(baseRenamer, new PermitionsChecker());

            renamer.Rename(null);
        }
コード例 #11
0
        public void CheckRenamer()
        {
            var renamer = new FileRenamer();
            var file    = new Mp3File("SampleFile.mp3");

            renamer.Rename(file);

            Assert.AreEqual("NewSampleFile.mp3", file.Path);
        }
コード例 #12
0
ファイル: LibraryTest.cs プロジェクト: taler0n/Students
        public void SimpleRenamer()
        {
            FileRenamer renamer = new FileRenamer();
            MP3File     file    = new MP3File("test.mp3");

            renamer.Rename(file);

            Assert.AreEqual("test_(new).mp3", file.Path);
        }
コード例 #13
0
 static FileRenamerTests()
 {
     _renamer     = generateRenamer();
     _filecount   = 18;
     _dllCount    = 9;
     _nonDllCount = _filecount - _dllCount;
     _renamer.FileExtensionFilter = new string[] { ".exe", ".config", ".pdb", ".xml", ".pdf" };
     _renamer.FileEndingsToRemove = new string[] { "-part", "-final", "-edit" };
 }
コード例 #14
0
        public void TestGetNewFullPath()
        {
            string path            = "../../../testdata/good.jpg";
            string folder          = Directory.GetParent(path).ToString();
            string newExpectedPath = Path.Combine(folder, $"{expected}.jpg");
            string result          = FileRenamer.GetNewFullPath(path);

            Assert.Equal(newExpectedPath, result);
        }
コード例 #15
0
            public void RenameExistingFileSameDigitCount()
            {
                var newFile = new FileInfo(@"c:\test\002-SomeNewFile.mp3");
                int newIndex = 5;
                int digitCount = 3;

                var renamer = new FileRenamer();
                var newName = renamer.GetNewFileName(newFile, newIndex, digitCount);

                newName.ShouldBe("005-SomeNewFile.mp3");
            }
コード例 #16
0
            public void RenameNewFileWithNumericPrefix()
            {
                var newFile = new FileInfo(@"c:\test\2SomeNewFile.mp3");
                int newIndex = 5;
                int digitCount = 3;

                var renamer = new FileRenamer();
                var newName = renamer.GetNewFileName(newFile, newIndex, digitCount);

                newName.ShouldBe("005-2SomeNewFile.mp3");
            }
コード例 #17
0
ファイル: LibraryTest.cs プロジェクト: taler0n/Students
        public void PermitionsCheckerRenamerSuccessful()
        {
            FileRenamer baseRenamer = new FileRenamer();
            FileRenamerPermitionsChecker renamer = new FileRenamerPermitionsChecker(baseRenamer,
                                                                                    new PermitionsChecker(), Permitions.Administrator);
            MP3File file = new MP3File("test.mp3");

            file.FilePermitions = Permitions.Guest;

            renamer.Rename(file);

            Assert.AreEqual("test_(new).mp3", file.Path);
        }
コード例 #18
0
        public void TestBadJpgNameShouldNotMove()
        {
            string path = "../../../testdata/blarg";

            var mock        = new MoverMock();
            var fileRenamer = new FileRenamer(mock);
            var files       = new List <string>();

            files.Add(path);
            fileRenamer.RenameFiles(files);
            Assert.Null(mock.from);
            Assert.Null(mock.to);
        }
コード例 #19
0
        public void MakeFilenameFromTags()
        {
            if (System.IO.File.Exists(@"tests\Led Zeppelin - Kashmir.mp3"))
            {
                System.IO.File.Delete(@"tests\Led Zeppelin - Kashmir.mp3");
            }
            System.IO.File.Copy(filePathForName, filePathForNameCopy);

            var renamer = new FileRenamer(directory);

            renamer.MakeFileNames(new string[] { filePathForNameCopy });

            Assert.AreEqual(true, System.IO.File.Exists(@"tests\Led Zeppelin - Kashmir.mp3"));
        }
コード例 #20
0
        public void TestValidJpgNameShouldMove()
        {
            string path           = "../../../testdata/IMG_20180613_152330.jpg";
            string expectedResult = GetExpectedResult(path, "jpg");

            var mock        = new MoverMock();
            var fileRenamer = new FileRenamer(mock);
            var files       = new List <string>();

            files.Add(path);
            fileRenamer.RenameFiles(files);
            Assert.Equal(mock.from, path);
            Assert.Equal(mock.to, expectedResult);
        }
コード例 #21
0
ファイル: LibraryTest.cs プロジェクト: taler0n/Students
        public void TimeMeasureRenamerSuccessful()
        {
            FileRenamer            baseRenamer = new FileRenamer();
            FileRenamerTimeMeasure renamer     = new FileRenamerTimeMeasure(baseRenamer);
            MP3File file = new MP3File("test.mp3");

            Assert.AreEqual(new TimeSpan(0L), renamer.ElapsedTime);

            renamer.Rename(file);

            Assert.AreEqual("test_(new).mp3", file.Path);
            Assert.IsNotNull(renamer.ElapsedTime);
            Assert.AreNotEqual(new TimeSpan(0L), renamer.ElapsedTime);
        }
コード例 #22
0
        public void MakeTagsFromFilename()
        {
            file = File.Create(filePathForTag);
            file.Tag.Performers = new string[] { };
            file.Tag.Title      = String.Empty;
            file.Save();

            var renamer = new FileRenamer(directory);

            renamer.MakeFileTags(new string[] { filePathForTag });

            file = File.Create(filePathForTag);
            Assert.AreEqual("Led Zeppelin", file.Tag.FirstPerformer);
            Assert.AreEqual("Stairway to Heaven", file.Tag.Title);
        }
コード例 #23
0
    void Rename(int index)
    {
        var entry = levelData[index];

        FileRenamer.Show(entry.File, entry.Dialogue);
        FileRenamer.NormalCallback = delegate(FileInfo old, FileInfo newFile) {
            //Debug.Log("N");
            entry.File = newFile;
            entry.Name = Path.GetFileNameWithoutExtension(newFile.FullName);
        };
        FileRenamer.DialogueCallback = delegate(FileInfo old, FileInfo newFile) {
            //Debug.Log("N2");
            entry.Dialogue = newFile;
        };
        FileRenamer.FinalCallback = Save;
        this.Repaint();
        //	GUILayout.Window(index, new Rect(0, 0, 100, 100).Centered(), DoRename, "Rename");
        //}
    }
コード例 #24
0
        public void Process(string[] args, MP3File[] files, Permitions userPermitions = Permitions.Guest)
        {
            if (files == null || files.Length == 0)
            {
                throw new ArgumentException("No files to process");
            }

            ArgumentsParser parser    = new ArgumentsParser();
            Arguments       arguments = parser.ParseArguments(args);

            foreach (var file in files)
            {
                string       message     = file.Path;
                IFileRenamer fileRenamer = new FileRenamer();

                if (arguments.IsCheckPermitions)
                {
                    IFileRenamer       oldFileRenamer = fileRenamer;
                    IPermitionsChecker checker        = new PermitionsChecker();
                    fileRenamer = new FileRenamerPermitionsChecker(oldFileRenamer, checker, userPermitions);
                }

                if (arguments.IsTimeMeasure)
                {
                    IFileRenamer oldFileRenamer = fileRenamer;
                    fileRenamer = new FileRenamerTimeMeasure(oldFileRenamer);
                }

                fileRenamer.Rename(file);

                message += " successfully renamed to " + file.Path;
                if (arguments.IsTimeMeasure)
                {
                    message += " in " + ((FileRenamerTimeMeasure)fileRenamer).ElapsedTime;
                }

                Console.WriteLine(message);
            }
        }
コード例 #25
0
 public void CtorTestEmptyStringDirectory()
 {
     var namer = new FileRenamer("");
 }
コード例 #26
0
 public void CtorTestNullDirectory()
 {
     var namer = new FileRenamer(null);
 }
コード例 #27
0
 public void CtorTestEmptyDirectory()
 {
     var namer = new FileRenamer(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "empty"));
 }
コード例 #28
0
 public void TestFileNotFoundShouldThrow()
 {
     Assert.Throws <FileNotFoundException>(() => FileRenamer.GetNewName("idontexist"));
 }
コード例 #29
0
        public void TestBadStringShouldThrow()
        {
            Exception ex = Assert.Throws <TimestampException>(() => FileRenamer.GetNewName("../../../testdata/blarg"));

            Assert.Equal("String blarg doesn't match any format.", ex.Message);
        }
コード例 #30
0
        public void TestVidStringShouldReturnExpected()
        {
            string result = FileRenamer.GetNewName("../../../testdata/VID_20180613_152330.mp4");

            Assert.Equal(expected, result);
        }
コード例 #31
0
        public void ValidEXIFDataShouldReturnExpected()
        {
            string result = FileRenamer.GetNewName("../../../testdata/good.jpg");

            Assert.Equal(expected, result);
        }
コード例 #32
0
        static private void readInput(string input)
        {
            List <string> arguments = split(input);

            if (arguments.Contains("rename"))
            {
                int renameIndex = arguments.IndexOf("rename");

                string directory     = arguments[renameIndex + 1];
                string matchString   = arguments[renameIndex + 2];
                string replaceString = arguments[renameIndex + 3];

                bool overwrite       = false;
                bool filter          = false;
                bool filterout       = false;
                bool subdirectories  = false;
                bool internalStrings = false;

                List <string> filterExt    = new List <string>();
                List <string> filterOutExt = new List <string>();

                for (int i = 0; i < arguments.Count; i++)
                {
                    switch (arguments[i])
                    {
                    case "o":
                    {
                        overwrite = true;
                        break;
                    }

                    case "f":
                    {
                        filter = true;
                        filterExt.Add(arguments[i + 1]);
                        i++;
                        break;
                    }

                    case "fo":
                    {
                        filterout = true;
                        filterOutExt.Add(arguments[i + 1]);
                        i++;
                        break;
                    }

                    case "s":
                    {
                        subdirectories = true;
                        break;
                    }

                        /*
                         * case "i":
                         * {
                         *  internalStrings = true;
                         *  break;
                         * }
                         */
                    }
                }

                FileRenamer renamer = new FileRenamer();

                renamer.renameInitialization(directory, matchString, replaceString, overwrite, internalStrings, subdirectories, filter, filterout, filterExt, filterOutExt);
            }

            if (arguments.Contains("search"))
            {
                int searchIndex = arguments.IndexOf("search");

                string directory   = arguments[searchIndex + 1];
                string matchString = arguments[searchIndex + 2];

                bool caseSensitive  = false;
                bool subdirectories = false;

                for (int i = 0; i < arguments.Count; i++)
                {
                    switch (arguments[i])
                    {
                    case "cs":
                    {
                        caseSensitive = true;
                        break;
                    }

                    case "s":
                    {
                        subdirectories = true;
                        break;
                    }
                    }
                }

                FileRenamer renamer = new FileRenamer();

                renamer.searchInitialization(directory, matchString, caseSensitive, subdirectories);
            }
        }
コード例 #33
0
        public void TestEmptyPathShouldThrow()
        {
            Exception ex = Assert.Throws <ArgumentException>(() => FileRenamer.GetNewName(""));

            Assert.Equal("Can't process empty string.", ex.Message);
        }