示例#1
0
        /// <summary>
        /// Finds and sets song artist, sets determines song title then returns if artist was identified.
        /// </summary>
        /// <returns></returns>
        private void setSongInfo()
        {
            string s1, s2;

            if (NewFileName.Contains('-'))
            {
                //Dividing character between artist and song title.
                int div = NewFileName.IndexOf("-");

                //Split filename into artist and song name, lower and trim string.
                s1 = NewFileName.Substring(0, div).ToLower().Trim();
                s2 = NewFileName.Substring(div + 1, NewFileName.Length - (div + 1)).ToLower().Trim();

                //If substring 1 contains a matching artist set filename with artist first.
                if (LibraryManager.checkArtist(s1))
                {
                    Artist      = StringUtils.formatText(s1);
                    Title       = StringUtils.formatText(s2);
                    NewFileName = Artist + " - " + Title;

                    artistFound = true;
                }
                //If substring 2 contains a matching artist set filename with artist first.
                else if (LibraryManager.checkArtist(s2))
                {
                    Artist      = StringUtils.formatText(s2);
                    Title       = StringUtils.formatText(s1);
                    NewFileName = Artist + " - " + Title;

                    artistFound = true;
                }
                else
                {
                    Artist      = StringUtils.formatText(s1);
                    Title       = StringUtils.formatText(s2);
                    NewFileName = Artist + " - " + Title;
                }
            }
        }
        public static void ReArrangeFiles(string FilePath, bool isMovedFromFolder)
        {
            // To Get All Files In Directory
            string[] files = Directory.GetFiles(FilePath);
            string   NewFileName; // declare varible will hold a new name of the file
            int      filenum;     //holds the file number to move it to the first of the name

            //loop through each file in directory
            foreach (var file in files)
            {
                /*
                 * General Case of the file name will be like this  Folder Name - File Name -mXX-XX .mp4
                 * mXX will represent folder name or set of releated files , -XX the file number in series
                 * here we take the file name from the full path and without extension '.*'
                 */
                NewFileName = file.Substring(file.LastIndexOf(@"\") + 1, file.LastIndexOf('.') - file.LastIndexOf(@"\") - 1);
                //Remove the folder name from downloaded file
                NewFileName = NewFileName.Substring(NewFileName.IndexOf('-') + 1);
                //Chek if the file moved from folder to Remove mxx from file name
                if (!isMovedFromFolder)
                {
                    // copy file number and move it to the beggining of the file name
                    NewFileName = NewFileName.Substring(NewFileName.LastIndexOf('m')) + "- " + NewFileName;
                }
                else
                {
                    // copy file number and move it to the beggining of the file name without mxx
                    NewFileName = NewFileName.Substring(NewFileName.LastIndexOf('-') + 1) + "- " + NewFileName;
                }
                //remove the file name from the end of file
                NewFileName = NewFileName.Remove(NewFileName.LastIndexOf('m') - 1);

                //In C# we can move cause we don't have rename , replace old path with new path and new file name and add extension
                File.Move(file, Path.GetDirectoryName(file) + @"\" + NewFileName + ".mp4");
            }
        }