移动文件夹

Posted on 2019-01-08 13:32  努力成长静待花开  阅读(133)  评论(0编辑  收藏  举报

实现效果:

  

知识运用:

  DirectoryInfo类的MoveTo方法

  public void MoveTo (string destDirName)

实现代码:

        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                DirectoryInfo Dinfo=new DirectoryInfo(textBox1.Text);
                string strPath = textBox2.Text + textBox1.Text.Substring(
                    textBox1.Text.LastIndexOf("\\")+1,textBox1.Text.Length-textBox1.Text.LastIndexOf("\\")-1);
                Dinfo.MoveTo(strPath);
            }
            catch{}
        }