private void toolStripMenuItemFileRename_Click(object sender, EventArgs e) { if (this.listView1.SelectedItems.Count > 0) { newNameForm = new NewName(); newNameForm.LabelText = "Введите новое имя"; if (DialogResult.OK == newNameForm.ShowDialog() && newNameForm.TextBoxText != "") { string newPath = Path.Combine(fullPathSelected, newNameForm.TextBoxText); foreach (ListViewItem item in this.listView1.SelectedItems) { if (Path.HasExtension(item.Text)) { try { FileInfo tempFileInfo = new FileInfo(Path.Combine(fullPathSelected, item.Text)); tempFileInfo.MoveTo(newPath); } catch (Exception ex) { MessageBox.Show(ex.Message, "Переименование файла " + newPath, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { try { DirectoryInfo tempDirInfo = new DirectoryInfo(Path.Combine(fullPathSelected, item.Text)); tempDirInfo.MoveTo(newPath); } catch (Exception ex) { MessageBox.Show(ex.Message, "Переименование папки " + newPath, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } LoadList(); UpdateTreeNode(fullPathSelected); } } }
private void toolStripMenuItemFileCreateFile_Click(object sender, EventArgs e) { newNameForm = new NewName(); newNameForm.LabelText = "Введите имя создаваемого файла"; newNameForm.TextBoxText = "Новый текстовый документ.txt"; if (DialogResult.OK == newNameForm.ShowDialog() && newNameForm.TextBoxText != "") { string newPath = Path.Combine(fullPathSelected, newNameForm.TextBoxText); try { File.Create(newPath); } catch (Exception ex) { MessageBox.Show(ex.Message, "Создание файла " + newPath, MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadList(); } }
private void toolStripMenuItemFileCreateFolder_Click(object sender, EventArgs e) { newNameForm = new NewName(); newNameForm.LabelText = "Введите имя создаваемой папки"; newNameForm.TextBoxText = "Новая папка"; if (DialogResult.OK == newNameForm.ShowDialog() && newNameForm.TextBoxText != "") { string newPath = Path.Combine(fullPathSelected, newNameForm.TextBoxText); try { MyFileManager.CreateDirectory(newPath); } catch (Exception ex) { MessageBox.Show(ex.Message, "Создание папки " + newPath, MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadList(); UpdateTreeNode(fullPathSelected); } }