Advanced File Info
The AdvancedFileInfo
class is part of the Chase CommonLib library, designed to provide additional information about a file, including its size representation in various units. This class extends the functionality of the standard System.IO.FileInfo
class by adding methods to convert file sizes to human-readable strings in different units.
Namespace
Constructors
AdvancedFileInfo(string file)
AdvancedFileInfo(string file)
Creates a new instance of the AdvancedFileInfo
class with the specified file path.
Parameters:
file
(string): The path of the file.
Properties
BaseInfo
(FileInfo)
BaseInfo
(FileInfo)The BaseInfo
property holds the base System.IO.FileInfo
object for the specified file path.
IsDirectory
(bool)
IsDirectory
(bool)The IsDirectory
property indicates whether the specified path represents a directory (true
) or not (false
).
Methods
SizeToString(long bytes, int places = 2, FileSizeUnit unit = FileSizeUnit.Bytes)
SizeToString(long bytes, int places = 2, FileSizeUnit unit = FileSizeUnit.Bytes)
Converts a file size in bytes to a human-readable string representation with the specified number of decimal places and unit.
Parameters:
bytes
(long): The size of the file in bytes.places
(int, optional): The number of decimal places to round the size. Default is 2.unit
(FileSizeUnit, optional): The unit of file size to use for representation (Bytes, Bits, or IbiBytes). Default is Bytes.
Returns: (string) A human-readable string representation of the file size.
Exceptions:
ArgumentException
: Thrown if an invalidunit
value is provided.
SizeToString(int places = 2, FileSizeUnit unit = FileSizeUnit.Bytes)
SizeToString(int places = 2, FileSizeUnit unit = FileSizeUnit.Bytes)
Converts the size of the file represented by this AdvancedFileInfo
object to a human-readable string representation with the specified number of decimal places and unit.
Parameters:
places
(int, optional): The number of decimal places to round the size. Default is 2.unit
(FileSizeUnit, optional): The unit of file size to use for representation (Bytes, Bits, or IbiBytes). Default is Bytes.
Returns: (string) A human-readable string representation of the file size.
Enum
FileSizeUnit
FileSizeUnit
An enum representing different file size units:
Bytes
: Represents file size in bytes (e.g., 1.2 MB).Bits
: Represents file size in bits (e.g., 1.2 Mb).IbiBytes
: Represents file size in binary bytes (e.g., 1.2 MiB).
Example Usage
This example demonstrates how to use the AdvancedFileInfo
class to check if a path is a directory and convert the file size to different units for a specified file.
Last updated
Was this helpful?