コード例 #1
0
        /// <summary>
        /// Step 3: Changes file names of all
        /// </summary>
        /// <param name="dir">The folder path to start in. Subfolders are recursively accessed.</param>
        public void NameChange(string dir = null)
        {
            if (dir == null)
            {
                dir = RootPath;
            }

            FilePropertiesReader directory_reader = new FilePropertiesReader(dir);

            // Loop through
            foreach (FileProperties fp in directory_reader.GetFilesAndDirectories())
            {
                if (fp.IsDirectory)
                {
                    NameChange(fp.Path);
                    continue;
                }
                string NewFileName = PropertiesFormatter.Format(fp);

                if (Path.GetFileName(fp.Path) != NewFileName)
                {
                    string NewPath = GetAvailableFilePath(dir, NewFileName);
                    // if the name is actually different, change it
                    File.Move(fp.Path, NewPath);
                    OnFileRenamed(new FileChangedEventArgs(fp.Path, NewPath));
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Step 2: Makes folders and moves files into folders based on root\artist\album\song.mp3
        /// </summary>
        /// <param name="RenameFiles">If true, this method also does Step 3 (to improve efficiency)</param>
        public void PackAll(bool RenameFiles)
        {
            FilePropertiesReader directory_reader = new FilePropertiesReader(RootPath);

            // Loop through all files in RootPath
            // move files into RootPath/<artist>/<album>/ based on each file's properties
            // create directories when necessary
            foreach (FileProperties fp in directory_reader.GetFiles())
            {
                string FileName = Path.GetFileName(fp.Path);
                string Artist   = Unknownify(fp.AnyArtist).MakeLegalPath(false);
                string Album    = Unknownify(fp.Album).MakeLegalPath(false);

                string ArtistDir      = Path.Combine(RootPath, Artist);
                string ArtistAlbumDir = Path.Combine(ArtistDir, Album);
                if (!Directory.Exists(ArtistAlbumDir))
                {
                    if (!Directory.Exists(ArtistDir))
                    {
                        // creating ArtistAlbumDir automatically creates ArtistDir
                        OnFolderCreated(new FolderCreatedEventArgs(ArtistDir));
                    }
                    Directory.CreateDirectory(ArtistAlbumDir);

                    OnFolderCreated(new FolderCreatedEventArgs(ArtistAlbumDir));
                }

                if (RenameFiles)
                {
                    // Do step 3's job more effiently while we're at it
                    FileName = PropertiesFormatter.Format(fp);
                    // Perhaps add an event here?
                }

                // File moved
                string new_path = GetAvailableFilePath(ArtistAlbumDir, FileName);
                File.Move(fp.Path, new_path);

                OnFileMoved(new FileChangedEventArgs(fp.Path, new_path));
            }
        }