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); } } } }