用C#做的软件在安装或首次运行时在D盘自动生成一个文件夹,并且包含四个子文件夹的代码怎么写?
展开全部
using System.IO;
string parentFolder = "文件夹名";
string[] folderArray = new string[]{"子文件夹1","子文件夹2","子文件夹3","子文件夹4"}
string parentFolderPath = string.Format{@"D:\{0}",parentFolder }
if (!Directory.Exists(parentFolderPath))
{
//没有自动生成文件夹
Directory.CreateDirectory(folderPath);
}
foreach(string folder in folderArray )
{
string folderPath = string.Format{@"{0}\{1}", parentFolderPath ,folder }
if(!Directory.Exists(folderPath)))
{
Directory.CreateDirectory(folderPath );
}
}
//是否四个子文件夹
DirectoryInfo theFolder = new DirectoryInfo(parentFolderPath );
if(theFolder.GetDirectories().Length == 4)
{
return true;
}
别说不懂,别吝啬分。
string parentFolder = "文件夹名";
string[] folderArray = new string[]{"子文件夹1","子文件夹2","子文件夹3","子文件夹4"}
string parentFolderPath = string.Format{@"D:\{0}",parentFolder }
if (!Directory.Exists(parentFolderPath))
{
//没有自动生成文件夹
Directory.CreateDirectory(folderPath);
}
foreach(string folder in folderArray )
{
string folderPath = string.Format{@"{0}\{1}", parentFolderPath ,folder }
if(!Directory.Exists(folderPath)))
{
Directory.CreateDirectory(folderPath );
}
}
//是否四个子文件夹
DirectoryInfo theFolder = new DirectoryInfo(parentFolderPath );
if(theFolder.GetDirectories().Length == 4)
{
return true;
}
别说不懂,别吝啬分。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询