如何在子文件夹中创建多个文件夹
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)。请给我建议.....
答案 0 :(得分:2)
CreateDirectory
也会在路径中创建所有子目录,因此您可以执行Directory.CreateDirectory("C:\\abc\\def\\ghi");
。