Skip to content

Convert variables like int, long to GB, MB, KB and a lot more

Notifications You must be signed in to change notification settings

mauricepreiss/FileSizeConverter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FileSizeConverter

Description

A small short API to convert file sizes from e.g. a disk, directory, file to any size.

Example:

  • Gigabyte to Megabyte
  • Terrabyte to Gigabyte
  • ... etc.

Just add it to your project via "Right Click > References > Add Reference", then select the DLL and happy converting. ;)

How to add a reference in Visual Studio: https://learn.microsoft.com/en-us/visualstudio/ide/managing-references-in-a-project?view=vs-2022

Usage

Import on top of your file

  using FileSizeConverter;

Use like this:

  string driveinfo = "Windows";
  DriveInfo drive = new DriveInfo(driveinfo);
  long size = drive.TotalSize;
  string GB = size.ToSize(SizeUnits.GB, DisplayUnitState.Shown)
  // Example Output: 2,55GB

Enums

Size Units (The value you want to convert the size in):

 public enum SizeUnits
 {
    Byte, KB, MB, GB, TB, PB, EB, ZB, YB
 }

Display Unit State (You want to have only the value or with it's unit state after it):

 public enum DisplayUnitState
 {
    Shown,
    Hidden
 }

Example:

Hidden: 2,54, Shown: 2,54GB

License

  • no copyright
  • free for commertical usage

Author

@mauricepreiss