会在D盘目录下创建一个名为test的空文件夹
代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApp4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if(textBox1.Text=="")
{
MessageBox.Show("输入创建文件夹的名称");
}
else
{
if(Directory.Exists(textBox1.Text))
{
MessageBox.Show("已存在该文件夹,请重新命名");
}
else
{
Directory.CreateDirectory(textBox1.Text);
}
}
}
}
}