修改文件及其目录的名称

实现效果:

  

知识运用:  

  File类的Move方法    //将指定文件移动到新位置

  public static void Move(string sourceFileName,string destFileName)

  Directory类的Move方法    //将文件或目录及其内容移动到新位置

  public static void Move(string sourceDirName,string destDirName)

实现代码:

        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox2.Text != string.Empty)
            {
                try
                {
                    Directory.Move(textBox1.Text, select + textBox2.Text);   //进行命名
                    Refrech(listBox1,select);                               //执行刷新
                }
                catch (Exception ex)                                        //捕获冲突
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
原文地址:https://www.cnblogs.com/feiyucha/p/10223018.html