20230614_SZLS_upperpc/NTADCP/FileManager.cs

65 lines
1.6 KiB
C#
Raw Normal View History

2023-07-24 07:35:05 +00:00
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);
}
}
}
}