/// <summary> /// 清除并写入文件内容, 并在控制台报告文件路径 /// </summary> /// <param name="abs_file_path">文件绝对路径</param> /// <param name="content">写入内容</param> public void ClearAndWriteFile(string abs_file_path, string content) { abs_file_path = ConvertTool.ToString(abs_file_path); if (!PathHelp.IsAbsolute(abs_file_path)) { Console.WriteLine("需要写入的文件名称错误: {0}", abs_file_path); return; } content = ConvertTool.ToString(content); File.Delete(abs_file_path); File.AppendAllText(abs_file_path, content); Console.WriteLine("清空并写入文件: {0}", abs_file_path); }
public CaseModel Func_IsAbsolute() { return(new CaseModel() { NameSign = @"是否绝对路径", ExeEvent = () => { KeyBoolean[] paths = new KeyBoolean[] { new KeyBoolean() { Key = null, Value = false }, new KeyBoolean() { Key = string.Empty, Value = false }, new KeyBoolean() { Key = "/", Value = false }, new KeyBoolean() { Key = "folder", Value = false }, new KeyBoolean() { Key = "folder/son", Value = false }, new KeyBoolean() { Key = "/folder/son", Value = false }, new KeyBoolean() { Key = "/folder/son/name.txt", Value = false }, new KeyBoolean() { Key = "C:/", Value = false }, new KeyBoolean() { Key = "C:/Users/Administrator", Value = false }, new KeyBoolean() { Key = "C:", Value = false }, new KeyBoolean() { Key = "C:\\", Value = true }, new KeyBoolean() { Key = "C:\\Users\\Administrator", Value = true }, new KeyBoolean() { Key = "C:\\Users\\Administrator\\name.txt", Value = true }, }; foreach (KeyBoolean item in paths) { if (PathHelp.IsAbsolute(item.Key) != item.Value) { Console.WriteLine("item.Key: {0} item.Value: {1}", item.Key, item.Value); return false; } } return true; }, }); }