创建文件夹

Posted on 2019-01-07 23:42  努力成长静待花开  阅读(123)  评论(0编辑  收藏  举报

实现效果:

  

知识运用:
  DirectoryInfo类的Create方法

  string对象的EndsWith方法

实现代码:

        private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog FBDialog = new FolderBrowserDialog();
            if (FBDialog.ShowDialog() == DialogResult.OK)
            { 
                string strPath=FBDialog.SelectedPath;
                if (strPath.EndsWith("\\"))
                    textBox1.Text = strPath;
                else
                    textBox1.Text = strPath + "\\";
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DirectoryInfo Dinfo = new DirectoryInfo(textBox1.Text+textBox2.Text);
            Dinfo.Create();
        }