private void BtnShowFolderFiles_Click(object sender, EventArgs e) { if (Directory.Exists(TbxPath.Text)) { DirectoryInfo directoryInfo = new DirectoryInfo(TbxPath.Text); FileInfo[] infos = directoryInfo.GetFiles(); foreach (FileInfo fileInfo in infos) { SetCursorDown(); if (IsFileFilter(fileInfo.Name))//custom icons to folders { RtbRenamedText.AppendText(fileInfo.Name + " - Ignored\n"); } else { RtbRenamedText.AppendText(fileInfo.Name + "\n"); } } } else { SetCursorDown(); AppendColoredTextToRtb(RtbRenamedText, "PATH DOES NOT EXIST\n", alertColor); } }
private void BtnClearRenamedRtb_Click(object sender, EventArgs e) { RtbRenamedText.Clear(); }
private void SetCursorDown() { RtbRenamedText.Select(RtbRenamedText.Text.Length, 0); }
private void BtnTransferFilesFromDownload_Click(object sender, EventArgs e) // work in progress { /* * works when " FileName - someting.Extension " * takes the string "Filename - something" and split by("-") * then searches the last season in the folder if exist * then places that episode there */ const string FILES_PATH = @"D:\torrent download\"; const string DESTINATION_PATH = @"D:\AN\Anime\"; string[] subdirectoryEntriesEntry = Directory.GetDirectories(FILES_PATH); // Loop through them to see if they have any other subdirectories foreach (string subdirectory in subdirectoryEntriesEntry) { LoadSubDirs(subdirectory); } void LoadSubDirs(string dir) { RtbRenamedText.AppendText(dir + Environment.NewLine); string[] subdirectoryEntries = Directory.GetDirectories(dir); DirectoryInfo directoryInfo = new DirectoryInfo(dir); FileInfo[] infos = directoryInfo.GetFiles(); foreach (FileInfo fileInfo in infos) { string SeriesName = GetSeriesName(fileInfo.Directory.Name); string SeasonNum = GetLatestSeason(SeriesName); string pathNeeded = SeriesName + '\\' + "Season " + SeasonNum + '\\'; File.Move(fileInfo.FullName, DESTINATION_PATH + pathNeeded + fileInfo.Name); AppendColoredTextToRtb(RtbRenamedText, "Moved file: " + fileInfo.Name, Color.Blue); } Directory.Delete(dir); foreach (string subdirectory in subdirectoryEntries) { LoadSubDirs(subdirectory); } } string GetLatestSeason(string SeriesName) { string[] currentSubdirectory = Directory.GetDirectories(DESTINATION_PATH); //find the series then the max season foreach (string directory in currentSubdirectory) { if (DESTINATION_PATH + SeriesName == directory) { int j = DESTINATION_PATH.Length + SeriesName.Length + 1 + 6; string[] seasons = Directory.GetDirectories(directory); int[] seasonsInNum = new int[seasons.Length]; for (int i = 0; i < seasons.Length; i++) { seasonsInNum[i] = Convert.ToInt32(seasons[i].Substring(DESTINATION_PATH.Length + SeriesName.Length + 7));//7 is the slash and the season } int maxValue = seasonsInNum.Max(); return(maxValue.ToString()); } } return("Error");///did not find the series in folder } string GetSeriesName(string directoryName) { string result = directoryName.Split('-')[0]; result = result.Substring(0, result.Length - 1); // no need the space at the end return(result); } }
private void BtnRenameVTwo_Click(object sender, EventArgs e) { string[] lines = FormatTextIntoLines(TbxPath.Text); for (int ind = 0; ind < lines.Length; ind++) { if (Directory.Exists(lines[ind])) { int[] numFilter; string usersPath = lines[ind]; if (usersPath[usersPath.Length - 1] != '\\') { usersPath += '\\'; } bool isNumberFirst = CbxIsNumberFirstV2.Checked; if (TbxFilterNumbersV1.Text != "") { string[] stringToNum; stringToNum = TbxFilterNumbersV1.Text.Split(' '); numFilter = new int[stringToNum.Length]; for (int i = 0; i < stringToNum.Length; i++) { if (stringToNum[i] == "") { continue; } numFilter[i] = Convert.ToInt32(stringToNum[i]); } } else { numFilter = null; } //get the directory info files and check if there is a path DirectoryInfo directoryInfo = new DirectoryInfo(usersPath); FileInfo[] infos = directoryInfo.GetFiles(); bool renameSuccess = true; foreach (FileInfo fileInfo in infos) { if (!IsFileLocked(fileInfo)) { try { if (IsFileFilter(fileInfo.Name)) { goto END; //filter file names } int numberFromTheString = GetNumberOutOfString(fileInfo.Name, fileInfo.Extension, isNumberFirst, numFilter); string seasonNum; //Season number of the current file string[] seasonAndNumberSplited = fileInfo.Directory.Name.Split(' '); //if the directory has season in it, will fail if no space if (seasonAndNumberSplited[0].ToLower() == "season") //if the directory name is season { string seriesName = fileInfo.Directory.Parent.Name; seasonNum = seasonAndNumberSplited[1]; string finalName = CreateFinalName(numberFromTheString, seasonNum, seriesName); File.Move(fileInfo.FullName, usersPath + finalName + fileInfo.Extension); SetCursorDown(); AppendColoredTextToRtb(RtbRenamedText, fileInfo.Name + " --> " + finalName + Environment.NewLine, Color.Blue); } else //if directory name was not season then create a season folder { string seriesName = fileInfo.Directory.Name; seasonNum = "1"; //set SeasonNum to 1 string finalName = CreateFinalName(numberFromTheString, seasonNum, seriesName); string newPath = fileInfo.DirectoryName + '\\' + "Season " + seasonNum + '\\'; if (!Directory.Exists(newPath)) { RtbRenamedText.Focus(); RtbRenamedText.AppendText("Created Folder: Season " + seasonNum + Environment.NewLine); Directory.CreateDirectory(newPath); } File.Move(fileInfo.FullName, newPath + finalName + fileInfo.Extension); SetCursorDown(); AppendColoredTextToRtb(RtbRenamedText, fileInfo.Name + " --> " + finalName + Environment.NewLine, Color.Blue); } } catch (IOException) { renameSuccess = false; AppendColoredTextToRtb(RtbRenamedText, fileInfo.Name + " Already exist\n", alertColor); } END :; } else { renameSuccess = false; AppendColoredTextToRtb(RtbRenamedText, fileInfo.Name + "Is being used\n", alertColor); } } if (renameSuccess) { SetCursorDown(); AppendColoredTextToRtb(RtbRenamedText, "Done Successfully\n", approveColor); } string CreateFinalName(int numberFromTheString, string seasonNum, string seriesName) { string helperName; string episodeHelper = "E"; if (numberFromTheString / 10 < 1) { episodeHelper = "E0"; } helperName = CreateHelperName(seasonNum, numberFromTheString, episodeHelper); return(seriesName + " - " + helperName); } string CreateHelperName(string seasonNum, int numberFromTheString, string episodeHelper) { if (seasonNum == "00" || seasonNum.ToLower() == "specials") { return("S" + seasonNum + episodeHelper + numberFromTheString.ToString()); } else if (Convert.ToInt32(seasonNum) <= 9) { return("S0" + seasonNum + episodeHelper + numberFromTheString.ToString()); } else { return("S" + seasonNum + episodeHelper + numberFromTheString.ToString()); } } } else { SetCursorDown(); AppendColoredTextToRtb(RtbRenamedText, "PATH DOES NOT EXIST\n", alertColor); } } if (lines.Length < 1) { SetCursorDown(); AppendColoredTextToRtb(RtbRenamedText, "PATH DOES NOT EXIST\n", alertColor); } }