写文件:
StreamWriter rw = System.IO.File.CreateText(System.Web.HttpContext.Current.Server.MapPath("~/") + "//CreateText.txt");
rw.WriteLine(new Exception().ToString());
rw.Flush();
rw.Close();
获取目录下匹配的文件集(不含子文件夹内匹配的文件):
System.IO.Directory.GetFiles(string path);
System.IO.Directory.GetFiles(string path, string searchPattern);
System.IO.Directory.GetFiles(string path, string searchPattern, SearchOption searchOption);
递归创建目录:
private void createdir(string filefullpath)
{
if (!File.Exists(filefullpath))
{
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);
}
}
}
}
}
调用:
createdir(Server.MapPath("/Data/EF/Test/"));