c#中自带函数不会递归创建文件夹,需要自己写函数。
参数为文件路径,如果文件不存在就递归判断其父文件夹是否存在,不存在的话就创建
private void createdir(string filefullpath)
{
bool bexistfile = false;
if (File.Exists(filefullpath))
{
bexistfile = true;
}
else //判断路径中的文件夹是否存在
{
string dirpath = filefullpath.Substring(0, filefullpath.LastIndexOf('\\'));
string[] pathes = dirpath.Split('\\');
if (pathes.Length > 1)
{
string path = pathes[0];
for (int i = 1; i < pathes.Length; i++)
{
path += "\\" + pathes[i];
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
}
}
}
}
Copyright © 2004-2024 Ynicp.com 版权所有 法律顾问:建纬(昆明)律师事务所 昆明市网翼通科技有限公司 滇ICP备08002592号-4