1.一些简单的文件操作
///
/// 建立文件
///
///
///
///
private void button1_Click(object sender, EventArgs e)
{
try
{
strpath = @textBox1.Text;//指定写入的路径
DirectoryInfo di = new DirectoryInfo(textBox1.Text);
if (di.Exists == false)//判断要建立的文件是否存在
{
Directory.CreateDirectory(strpath);
}
else
{
MessageBox.Show("您要建立的文件已经存在!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
///
/// 删除
///
///
///
private void button2_Click(object sender, EventArgs e)
{
try
{
DirectoryInfo di = new DirectoryInfo(strpath);
if (di.Exists == true)
{
Directory.Delete(strpath);
}
else
{
MessageBox.Show("您输入的目录不存在!!!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
///
/// 移动
///
///
///
private void button3_Click(object sender, EventArgs e)
{
try
{
//DirectoryInfo di = new DirectoryInfo(strpath);
//di.MoveTo(@textBox2.Text);
Directory.Move(strpath, @textBox2.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}