我已经有了一个目录位置,如何创建所有的目录?例如,C:\ Match \Upload将创建匹配和子目录Upload,如果它不存在。
使用C# 3.0
谢谢
发布于 2009-11-05 22:15:57
Directory.CreateDirectory(@"C:\Match\Upload")将为您解决所有这些问题。你不需要创建所有的子目录!create directory方法为您创建所有目录和子目录。
发布于 2009-11-05 22:18:12
if (!System.IO.Directory.Exists(@"C:\Match\Upload"))
{
System.IO.Directory.CreateDirectory(@"C:\Match\Upload");
}发布于 2015-07-07 02:01:49
下面是一个包含DirectoryInfo对象的示例,该对象将创建目录及其所有子目录:
var path = @"C:\Foo\Bar";
new System.IO.DirectoryInfo(path).Create();如果路径已经存在,则调用Create()不会出错。
如果它是一个文件路径,您可以执行以下操作:
var path = @"C:\Foo\Bar\jazzhands.txt";
new System.IO.FileInfo(path).Directory.Create();https://stackoverflow.com/questions/1680836
复制相似问题