public static void WriteAllBytes(string path, byte[] contents) { string realPath = PathExpress.ResolvePath(path); DirectoryExpress.CreateParentDirectory(realPath); File.WriteAllBytes(realPath, contents); }
public static FileStream Create(string path, int bufferSize, FileOptions fileOptions, FileSecurity fileSecurity) { string realPath = PathExpress.ResolvePath(path); DirectoryExpress.CreateParentDirectory(realPath); return(File.Create(path, bufferSize, fileOptions, fileSecurity)); }
public static void PrependAllLines(string path, List <string> contents, Encoding encoding = null) { string realPath = PathExpress.ResolvePath(path); DirectoryExpress.CreateParentDirectory(realPath); IList <string> oldContents = new List <string>(); if (File.Exists(realPath)) { oldContents = File.ReadAllLines(realPath) .ToList(); } IList <string> newContents = new List <string>(contents); foreach (string oldContent in oldContents) { newContents.Add(oldContent); } if (encoding == null) { File.WriteAllLines(realPath, newContents); } else { File.WriteAllLines(realPath, newContents, encoding); } }
public static FileStream Create(string path, int bufferSize) { string realPath = PathExpress.ResolvePath(path); DirectoryExpress.CreateParentDirectory(realPath); return(File.Create(path, bufferSize)); }
public static FileDescriptor SaveToDisk(string path, byte[] contents, bool overwrite = false) { string realPath = PathExpress.ResolvePath(path); DirectoryExpress.CreateParentDirectory(realPath); if (overwrite && File.Exists(realPath)) { File.Delete(realPath); } using (Stream outputStream = new FileStream(realPath, FileMode.CreateNew)) { outputStream.Write(contents, 0, contents.Length); } FileGetFileDescriptorArgument fileGetFileDecriptorArgument = new FileGetFileDescriptorArgument { Path = realPath, IncludePathInfo = true, IncludeAttribute = true, IncludeMd5 = true, IncludeSha1 = true, IncludeSha256 = true, IncludeSha512 = true }; FileDescriptor fileDescriptor = GetFileDescriptor(fileGetFileDecriptorArgument); return(fileDescriptor); }
public static FileDescriptor SaveToDisk(string path, Stream stream, bool overwrite = false) { string realPath = PathExpress.ResolvePath(path); DirectoryExpress.CreateParentDirectory(realPath); if (overwrite && File.Exists(realPath)) { File.Delete(realPath); } using (Stream outputStream = new FileStream(realPath, FileMode.CreateNew)) { if (stream.CanSeek) { stream.Position = 0; } stream.CopyTo(outputStream, TfxCentral.BufferLength); } FileGetFileDescriptorArgument fileGetFileDecriptorArgument = new FileGetFileDescriptorArgument { Path = realPath, IncludePathInfo = true, IncludeAttribute = true, IncludeMd5 = true, IncludeSha1 = true, IncludeSha256 = true, IncludeSha512 = true }; FileDescriptor fileDescriptor = GetFileDescriptor(fileGetFileDecriptorArgument); return(fileDescriptor); }
public static void Move(string sourcePath, string tartgetPath) { string realSourcePath = PathExpress.ResolvePath(sourcePath); string realTargetPath = PathExpress.ResolvePath(tartgetPath); DirectoryExpress.CreateParentDirectory(tartgetPath); File.Move(realSourcePath, realTargetPath); }
public static void Replace(string sourcePath, string tartgetPath, string backupPath, bool ignoreMetadataErrors = false) { string realSourcePath = PathExpress.ResolvePath(sourcePath); string realTargetPath = PathExpress.ResolvePath(tartgetPath); string realBackupPath = PathExpress.ResolvePath(backupPath); DirectoryExpress.CreateParentDirectory(tartgetPath); File.Replace(realSourcePath, realTargetPath, realBackupPath, ignoreMetadataErrors); }
public static void WriteAllText(string path, string contents, Encoding encoding = null) { string realPath = PathExpress.ResolvePath(path); DirectoryExpress.CreateParentDirectory(realPath); if (encoding == null) { File.WriteAllText(realPath, contents); } else { File.WriteAllText(realPath, contents, encoding); } }
public static void AppendAllLines(string path, IEnumerable <string> contents, Encoding encoding = null) { string realPath = PathExpress.ResolvePath(path); DirectoryExpress.CreateParentDirectory(realPath); if (encoding == null) { File.AppendAllLines(realPath, contents); } else { File.AppendAllLines(realPath, contents, encoding); } }
public static void ExtractManifestResources(Assembly assembly, string source, string target, bool overwrite = false) { string realTarget = PathExpress.ResolvePath(target); if (overwrite == false && File.Exists(realTarget)) { return; } DirectoryExpress.CreateParentDirectory(realTarget); using (Stream reader = assembly.GetManifestResourceStream(source)) { if (reader == null) { throw new NullReferenceException(nameof(reader)); } Stream writer = File.Create(realTarget); _ = reader.Seek(0, SeekOrigin.Begin); reader.CopyTo(writer); writer.Close(); } }
private static FileStream OpenInner(string path, FileMode fileMode, FileAccess?fileAccess = null, FileShare?fileShare = null) { string realPath = PathExpress.ResolvePath(path); if (fileMode == FileMode.Append || fileMode == FileMode.Create || fileMode == FileMode.CreateNew || fileMode == FileMode.OpenOrCreate) { DirectoryExpress.CreateParentDirectory(realPath); } if (fileAccess == null) { return(File.Open(realPath, fileMode)); } else if (fileShare == null) { return(File.Open(realPath, fileMode, fileAccess.Value)); } else { return(File.Open(realPath, fileMode, fileAccess.Value, fileShare.Value)); } }
public static void PrependAllText(string path, string content, Encoding encoding = null) { string realPath = PathExpress.ResolvePath(path); DirectoryExpress.CreateParentDirectory(realPath); string oldContent = string.Empty; if (File.Exists(realPath)) { oldContent = File.ReadAllText(realPath); } string newContent = content + oldContent; if (encoding == null) { File.WriteAllText(realPath, newContent); } else { File.WriteAllText(realPath, newContent, encoding); } }
static DirectoryExpress() { s_instance = new DirectoryExpress(); }