Provides extension methods for the DirectoryInfo class.
public static class DirectoryInfoExtensions
FileInfo CombineFileInfo(this DirectoryInfo directoryInfo, string[] paths)Summary: Combines the directory path with additional sub-paths to create a FileInfo object.
Parameters:
directoryInfo
- The base directory information.
paths
- An array of sub-paths to combine with the base directory.Returns: A FileInfo object representing the combined path.
long GetByteSize(this DirectoryInfo directoryInfo, string searchPattern = *.*, SearchOption searchOption = AllDirectories)Summary: Gets the byte size.
Parameters:
directoryInfo
- The directory information.
searchPattern
- The search pattern.
searchOption
- The search option.
FileInfo GetFileInfo(this DirectoryInfo directoryInfo, string file)Summary: Get the file information.
Parameters:
directoryInfo
- The directory information.
file
- The file.
long GetFilesCount(this DirectoryInfo directoryInfo, string searchPattern = *.*, SearchOption searchOption = AllDirectories)Summary: Gets the files count.
Parameters:
directoryInfo
- The directory information.
searchPattern
- The search pattern.
searchOption
- The search option.
FileInfo[] GetFilesForAuthorizedAccess(this DirectoryInfo directoryInfo, string searchPattern = *.*, SearchOption searchOption = TopDirectoryOnly)Summary: Gets the files as GetFiles, but skip files and folders with unauthorized access.
Parameters:
directoryInfo
- The directory information.
searchPattern
- The search pattern.
searchOption
- The search option.
long GetFoldersCount(this DirectoryInfo directoryInfo, string searchPattern = *, SearchOption searchOption = AllDirectories)Summary: Gets the folders count.
Parameters:
directoryInfo
- The directory information.
searchPattern
- The search pattern.
searchOption
- The search option.
string GetPrettyByteSize(this DirectoryInfo directoryInfo, string searchPattern = *.*, SearchOption searchOption = AllDirectories)Summary: Gets the byte size as pretty formatted text like '1.933.212.103 bytes'.
Parameters:
directoryInfo
- The directory information.
searchPattern
- The search pattern.
searchOption
- The search option.
string GetPrettySize(this DirectoryInfo directoryInfo, string searchPattern = *.*, SearchOption searchOption = AllDirectories)Summary: Gets the byte size as pretty formatted text like '1.82 GB'.
Parameters:
directoryInfo
- The directory information.
searchPattern
- The search pattern.
searchOption
- The search option.
Extension methods for the System.IO.FileInfo
class.
public static class FileInfoExtensions
byte[] ReadToByteArray(this FileInfo fileInfo)Summary: Reads to byte array.
Parameters:
fileInfo
- The file information.Returns: Return a byte array from the file
Task<byte[]> ReadToByteArrayAsync(this FileInfo fileInfo, CancellationToken cancellationToken = null)Summary: Reads to byte array.
Parameters:
fileInfo
- The file information.
cancellationToken
- The cancellation token.Returns: Return a byte array from the file
MemoryStream ReadToMemoryStream(this FileInfo fileInfo)Summary: Reads to
System.IO.MemoryStream
.Parameters:
fileInfo
- The file information.Returns: Return a
System.IO.MemoryStream
from the file
Task<MemoryStream> ReadToMemoryStreamAsync(this FileInfo fileInfo, CancellationToken cancellationToken = null)Summary: Reads to
System.IO.MemoryStream
.Parameters:
fileInfo
- The file information.
cancellationToken
- The cancellation token.Returns: Return a
System.IO.MemoryStream
from the file
Extensions for the System.IO.Stream
class.
public static class MemoryStreamExtensions
string ToString(this MemoryStream stream, Encoding encoding = null)Summary: Converts to string.
Parameters:
stream
- The stream.
encoding
- The encoding.
Extensions for the System.IO.Stream
class.
public static class StreamExtensions
Stream CopyToStream(this Stream stream, int bufferSize = 4096)Summary: Copy to stream.
Parameters:
stream
- The stream.
bufferSize
- Size of the buffer.
byte[] ToBytes(this Stream stream)Summary: Converts to bytes.
Parameters:
stream
- The stream.
string ToStringData(this Stream stream)Summary: Converts to string.
Parameters:
stream
- The stream.