65 lines
1.6 KiB
C#
65 lines
1.6 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.IO;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
|
|||
|
|
namespace NTADCP
|
|||
|
|
{
|
|||
|
|
//文件及文件夹管理器
|
|||
|
|
public class FileManager
|
|||
|
|
{
|
|||
|
|
//检测并创建文件存储路径
|
|||
|
|
public static bool Path_Create(string path, string filename)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
if (!System.IO.Directory.Exists(path))
|
|||
|
|
{
|
|||
|
|
Directory.CreateDirectory(path);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (string.IsNullOrEmpty(filename))
|
|||
|
|
return true;
|
|||
|
|
|
|||
|
|
if (!path.EndsWith(@"\"))
|
|||
|
|
path += @"\";
|
|||
|
|
|
|||
|
|
if (!System.IO.File.Exists(path + filename))
|
|||
|
|
{
|
|||
|
|
FileStream stream = System.IO.File.Create(path + filename);
|
|||
|
|
stream.Close();
|
|||
|
|
stream.Dispose();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
catch (Exception)
|
|||
|
|
{
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
//文件读取
|
|||
|
|
|
|||
|
|
|
|||
|
|
//文件写入
|
|||
|
|
/// <summary>
|
|||
|
|
/// txt文档自动保存
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="logstring"></param>
|
|||
|
|
public static void AddLgoToTXT(string _file_name, string path, string logstring)
|
|||
|
|
{
|
|||
|
|
Path_Create(path, _file_name);
|
|||
|
|
if (!path.EndsWith(@"\"))
|
|||
|
|
path += @"\";
|
|||
|
|
using (StreamWriter writer = new StreamWriter(path + _file_name, true))
|
|||
|
|
{
|
|||
|
|
writer.WriteLine(logstring);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|