예제 #1
0
 private void ContextMenuCreateFolder_Click(object sender, EventArgs e)
 {
     using (FormRename formRename = new FormRename("Новая папка"))
     {
         if (formRename.ShowDialog() == DialogResult.OK)
         {
             DirectoryInfo dirInfo = new DirectoryInfo(textBoxPath.Text + "\\" + formRename.textBoxRenameField.Text);
             if (!dirInfo.Exists)
             {
                 dirInfo.Create();
             }
             else
             {
                 MessageBox.Show("Папка с таким именем уже существует");
             }
         }
     }
     UpdateListView(textBoxPath.Text);
 }
예제 #2
0
        private void MenuItemRename_Click(object sender, EventArgs e)
        {
            GetSelectedObjects();

            if (selectedFolders.Count == 1 && selectedFiles.Count == 0)
            {
                DirectoryInfo dirInfo = new DirectoryInfo(selectedFolders[0]);
                if (dirInfo.Exists)
                {
                    string newName = dirInfo.Name;
                    using (FormRename formRename = new FormRename(newName))
                    {
                        if (formRename.ShowDialog() == DialogResult.OK)
                        {
                            newName = formRename.textBoxRenameField.Text;
                            Directory.Move(dirInfo.FullName, textBoxPath.Text + "\\" + newName);
                        }
                    }
                }
            }
            else if (selectedFolders.Count == 0 && selectedFiles.Count == 1)
            {
                FileInfo fileInfo = new FileInfo(selectedFiles[0]);
                if (fileInfo.Exists)
                {
                    string newName = fileInfo.Name;
                    using (FormRename formRename = new FormRename(newName))
                    {
                        if (formRename.ShowDialog() == DialogResult.OK)
                        {
                            newName = formRename.textBoxRenameField.Text;
                            Directory.Move(fileInfo.FullName, textBoxPath.Text + "\\" + newName);
                        }
                    }
                }
            }
            UpdateListView(textBoxPath.Text);
        }