/// <summary> /// This member displays a sample of what a file in the rename from /// directory will look like renamed, based on the user input. /// </summary> /// <param name="show">If true, the sample is shown, otherwise, it is hidden.</param> private void ShowRenameSample(bool show) { m_renameSample.Text = string.Empty; string fromToken = m_fromTokenToReplace.Text; string toToken = m_toToken.Text.Trim(); if (show && !toToken.Equals(fromToken, StringComparison.CurrentCultureIgnoreCase)) { string fromPath = Convert.ToString(m_fromFolder.Tag); DirectoryInfo directoryInfo = new DirectoryInfo(fromPath); FileInfo[] files = directoryInfo.GetFiles(); if (files.Count() > 0) { FileInfo file = files[0]; RenameFileInfo renameFileInfo = GetRenameFileInfo(file); string fromFileName = renameFileInfo.FromFileName; string toFileName = renameFileInfo.ToFileName; string renameSample = string.Format("Rename from {0} to {1}", fromFileName, toFileName); m_renameSample.Text = renameSample; // Bold the "From" and "To" file names so they stand out... Font boldFont = new Font(m_renameSample.Font, FontStyle.Bold); m_renameSample.Select(m_renameSample.Text.IndexOf(fromFileName), fromFileName.Length); m_renameSample.SelectionFont = boldFont; m_renameSample.Select(m_renameSample.Text.IndexOf(toFileName), toFileName.Length); m_renameSample.SelectionFont = boldFont; } } }
private bool DoRename(out int renamedCount) { renamedCount = 0; try { try { string fromPath = Convert.ToString(m_fromFolder.Tag); DirectoryInfo directoryInfo = new DirectoryInfo(fromPath); foreach (FileInfo file in directoryInfo.GetFiles()) { RenameFileInfo renameFileInfo = GetRenameFileInfo(file); string fromFullFileName = renameFileInfo.FromFullFileName; string toFullFileName = renameFileInfo.ToFullFileName; File.Move(fromFullFileName, toFullFileName); ListViewItem listViewItem = m_renameStatus.Items.Add("OK"); listViewItem.ToolTipText = string.Format("Copied [{0}] to [{1}]", fromFullFileName, toFullFileName); listViewItem.SubItems.Add(Path.GetFileName(fromFullFileName)); listViewItem.SubItems.Add(Path.GetFileName(toFullFileName)); ++renamedCount; } ResizeListViewColumns(); this.RenameComplete = true; return(true); } catch (Exception e) { MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } finally { } return(false); }