Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.90 KB | None | 0 0
  1. public void Rename(ListView list, bool left)
  2.         {
  3.             string path = list.SelectedItems[0].Text;
  4.             string currentPath;
  5.  
  6.             if (left)
  7.                 currentPath = string.Format(@"{0}\\{1}", CurrentPathLeft, path);
  8.             else
  9.                 currentPath = string.Format(@"{0}\\{1}", CurrentPathRight, path);
  10.             LabelForm labelForm = new LabelForm(LabelForm.FormType.Uncategorized);
  11.             labelForm.ShowDialog();
  12.             try
  13.             {
  14.                 if (list.SelectedItems[0].ImageIndex == 0)
  15.                 {
  16.                     if (labelForm.done)
  17.                     {
  18.                         if (!Directory.Exists(currentPath + "\\" + labelForm.text))
  19.                         {
  20.                             Folder folder = new Folder(currentPath);
  21.                             folder.Rename(labelForm.text);
  22.                         }
  23.                         else
  24.                         {
  25.                             MessageBox.Show("Folder already exists", "Error");
  26.                         }
  27.                     }
  28.                 }
  29.                 else
  30.                 {
  31.                     if (!File.Exists(currentPath + "\\" + labelForm.text))
  32.                     {
  33.                         if (labelForm.done)
  34.                         {
  35.                             GenericFile commonFile = new GenericFile(currentPath);
  36.                             commonFile.Rename(labelForm.text);
  37.                         }
  38.                         labelForm.Dispose();
  39.                     }
  40.                     else
  41.                     {
  42.                         MessageBox.Show("File already exists", "Error");
  43.                     }
  44.                 }
  45.             }
  46.             catch (Exception error)
  47.             {
  48.                 labelForm.Dispose();
  49.                 MessageBox.Show(error.Message.ToString(), "Error");
  50.             }
  51.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement