public static void AppendAllLines(string path, IEnumerable <string> contents, Encoding encoding = null) { DirectoryExtension.Create(path); if (encoding is null) { File.AppendAllLines(path, contents); } else { File.AppendAllLines(path, contents, encoding); } }
public static void AppendAllText(string path, string contents, Encoding encoding = null) { DirectoryExtension.Create(path); if (encoding is null) { File.AppendAllText(path, contents); } else { File.AppendAllText(path, contents, encoding); } }
public static FileStream Create(string path, int?bufferSize = null, FileOptions?options = null) { DirectoryExtension.Create(path); if (options != null && bufferSize != null) { return(File.Create(path, (int)bufferSize, (FileOptions)options)); } if (bufferSize != null) { return(File.Create(path, (int)bufferSize)); } return(File.Create(path)); }
public static void Move(string sourceFileName, string destFileName, bool overwrite = false) { if (!File.Exists(sourceFileName)) { return; } DirectoryExtension.Create(destFileName); if (!overwrite && File.Exists(destFileName)) { return; } if (File.Exists(destFileName)) { File.Delete(destFileName); } File.Move(sourceFileName, destFileName); }
public static bool Copy(string sourceFileName, string destFileName, bool overwrite = false) { if (!File.Exists(sourceFileName)) { return(false); } DirectoryExtension.Create(destFileName); try { File.Copy(sourceFileName, destFileName, overwrite); return(true); } catch { return(false); } }