如何在子文件夹中创建许多文件夹.....

本文关键字:文件夹 许多 创建 | 更新日期: 2023-09-27 18:31:10

如何在一个子文件夹中创建多个文件夹

 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Windows.Forms;
 using System.IO;
  namespace Progressbar
 {
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    private void button1_Click(object sender, EventArgs e)
    {
    string path = @"A:'DMS'SCOSTADL";
         try       
         {        
             // Determine whether the directory exists.
             if (Directory.Exists(path))             
             {  
                 MessageBox.Show("Paths Exists already!!!!!!!!!");
                 return;
                  }
             // Try to create the directory.
              DirectoryInfo di = Directory.CreateDirectory(path);
             MessageBox.Show("Directory Created Successfully....!");
             } 
        catch (Exception e)         
         {
             Console.WriteLine("The process failed: {0}", e.ToString());
           }
             finally { }
         }
        }
         }

在这个例子中,我能够创建一个文件夹(DMS)和子文件夹(SCOSTADL),我想创建许多子文件夹以及子文件夹(SCOSTADL)。

如何在子文件夹中创建许多文件夹.....

CreateDirectory也会在路径中创建所有子目录,因此您可以执行Directory.CreateDirectory("C:''abc''def''ghi");