private void ProcessReplaceMethod(StackPanel sp, string id) { var ddBtn = LogicalTreeHelper.FindLogicalNode(sp, "ddBtn") as DropDownButton; var cb = LogicalTreeHelper.FindLogicalNode(ddBtn, "checkBox") as CheckBox; StackPanel sp1 = ddBtn.DropDownContent as StackPanel; var tbTextReplaced = LogicalTreeHelper.FindLogicalNode(sp1, "tbTextReplaced") as TextBox; var tbReplaceWith = LogicalTreeHelper.FindLogicalNode(sp1, "tbReplaceWith") as TextBox; if (cb.IsChecked == true) { if (id == "file") { foreach (var record in recordFiles) { if (!String.IsNullOrEmpty(tbTextReplaced.Text)) { record.NewFilename = NameProcessor.Replace(record.NewFilename, tbTextReplaced.Text, tbReplaceWith.Text); } } } else { foreach (var record in recordFolders) { if (!String.IsNullOrEmpty(tbTextReplaced.Text)) { record.NewFoldername = NameProcessor.Replace(record.NewFoldername, tbTextReplaced.Text, tbReplaceWith.Text); } } } } }
private void RenameFolder() { // append number to dupplicate files if need var rule = cbFolderNameCollisionRule.SelectedItem as ComboBoxItem; var strRule = rule.Content.ToString(); if (string.Equals(strRule, "AppendNumber")) { for (var i = 0; i < recordFolders.Count - 1; ++i) { if (!string.Equals(recordFolders[i].FolderError, "")) { string filename = ""; string extension = ""; var count = 2; for (var j = i + 1; j < recordFolders.Count; ++j) { if (string.Equals(recordFolders[i].NewFoldername, recordFolders[j].NewFoldername)) { NameProcessor.PreProcess(recordFolders[j].NewFoldername, ref filename, ref extension); recordFolders[j].NewFoldername = filename + count + extension; recordFolders[j].FolderError = ""; ++count; } } NameProcessor.PreProcess(recordFolders[i].NewFoldername, ref filename, ref extension); recordFolders[i].NewFoldername = filename + 1 + extension; recordFolders[i].FolderError = ""; recordFolders[i].FolderError = ""; } } } foreach (var record in recordFolders) { if (record.FolderError == "") { string oldName = record.FolderPath + "\\" + record.Foldername; string newName = record.FolderPath + "\\" + record.NewFoldername; string tmp = record.FolderPath + "\\" + NameProcessor.UniqueName(record.FolderPath); Directory.CreateDirectory(tmp); // actual rename Directory.Move(oldName, tmp + "\\" + record.NewFoldername); Directory.Move(tmp + "\\" + record.NewFoldername, record.FolderPath + "\\" + record.NewFoldername); Directory.Delete(tmp); // virtual rename record.Foldername = string.Copy(record.NewFoldername); } } foreach (var record in recordFolders) { record.NewFoldername = ""; } }
private void ProcessUniqueNameMethod(StackPanel sp, string id) { var btn = LogicalTreeHelper.FindLogicalNode(sp, "btn") as Button; var cb = LogicalTreeHelper.FindLogicalNode(btn, "checkBox") as CheckBox; if (cb.IsChecked == true) { if (id == "file") { foreach (var record in recordFiles) { record.NewFilename = NameProcessor.UniqueName(record.NewFilename); } } else { foreach (var record in recordFolders) { record.NewFoldername = NameProcessor.UniqueName(record.NewFoldername); } } } }
private void ProcessMoveMethod(StackPanel sp, string id) { var ddBtn = LogicalTreeHelper.FindLogicalNode(sp, "ddBtn") as DropDownButton; var cb = LogicalTreeHelper.FindLogicalNode(ddBtn, "checkBox") as CheckBox; StackPanel sp1 = ddBtn.DropDownContent as StackPanel; var tbMoveFrom = LogicalTreeHelper.FindLogicalNode(sp1, "tbMoveFrom") as TextBox; var tbMoveCount = LogicalTreeHelper.FindLogicalNode(sp1, "tbMoveCount") as TextBox; var tbMoveTo = LogicalTreeHelper.FindLogicalNode(sp1, "tbMoveTo") as TextBox; if (cb.IsChecked == true) { if (id == "file") { foreach (var record in recordFiles) { if (!String.IsNullOrEmpty(tbMoveFrom.Text) && !String.IsNullOrEmpty(tbMoveCount.Text) && !String.IsNullOrEmpty(tbMoveTo.Text)) { record.NewFilename = NameProcessor.Move(record.NewFilename, int.Parse(tbMoveFrom.Text), int.Parse(tbMoveCount.Text), int.Parse(tbMoveTo.Text)); } } } else { foreach (var record in recordFolders) { if (!String.IsNullOrEmpty(tbMoveFrom.Text) && !String.IsNullOrEmpty(tbMoveCount.Text) && !String.IsNullOrEmpty(tbMoveTo.Text)) { record.NewFoldername = NameProcessor.Move(record.NewFoldername, int.Parse(tbMoveFrom.Text), int.Parse(tbMoveCount.Text), int.Parse(tbMoveTo.Text)); } } } } }
private void ProcessNewCaseMethod(StackPanel sp, string id) { var ddBtn = LogicalTreeHelper.FindLogicalNode(sp, "ddBtn") as DropDownButton; var cb = LogicalTreeHelper.FindLogicalNode(ddBtn, "checkBox") as CheckBox; StackPanel sp1 = ddBtn.DropDownContent as StackPanel; var radUpper = LogicalTreeHelper.FindLogicalNode(sp1, "radUpper") as RadioButton; var radLower = LogicalTreeHelper.FindLogicalNode(sp1, "radLower") as RadioButton; var radUpperFirst = LogicalTreeHelper.FindLogicalNode(sp1, "radUpperFirst") as RadioButton; if (cb.IsChecked == true) { if (id == "file") { if (radUpper.IsChecked == true) { foreach (var record in recordFiles) { record.NewFilename = NameProcessor.ToUpper(record.NewFilename); } } else if (radLower.IsChecked == true) { foreach (var record in recordFiles) { record.NewFilename = NameProcessor.ToLower(record.NewFilename); } } else if (radUpperFirst.IsChecked == true) { foreach (var record in recordFiles) { record.NewFilename = NameProcessor.ToUpperFirstLetterOfWords(record.NewFilename); } } } else { if (radUpper.IsChecked == true) { foreach (var record in recordFolders) { record.NewFoldername = NameProcessor.ToUpper(record.NewFoldername); } } else if (radLower.IsChecked == true) { foreach (var record in recordFolders) { record.NewFoldername = NameProcessor.ToLower(record.NewFoldername); } } else if (radUpperFirst.IsChecked == true) { foreach (var record in recordFolders) { record.NewFoldername = NameProcessor.ToUpperFirstLetterOfWords(record.NewFoldername); } } } } }