在此目录中创建目录并保存文件。 [英] Create directory and save files on this directory.
本文介绍了在此目录中创建目录并保存文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨朋友
我想要定义一个字符串例如
string path =d:\\first\text.txt;
i想要创建文件夹(如果它不存在)然后创建文件。
谢谢。
Hi Friends
I want o define a string for example
string path="d:\\first\text.txt";
i want to create the folder(if it does not exist) and then create the file.
thank you.
推荐答案
你需要按照这些方式做点什么
You would need to do something along these lines
using System.IO;
string pathToFile = @"c:\temp\directorythatdoesntexist\file.txt";
if (!Directory.Exists(Path.GetDirectoryName(pathToFile)))
{
Directory.CreateDirectory(Path.GetDirectoryName(pathToFile));
}
File.Create(pathToFile);
这篇关于在此目录中创建目录并保存文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文