Tag Archives: F# static library

A Utilitarian F# Library

I started building an F# library that could be used to hold housekeeping routines. This is the start of that library.

namespace Toa.volLib
open System
open System.Threading
open System.Collections.Generic
open System.Text
open System.IO
open Microsoft.Win32

type DiskFreeLevels =
  | GB1   = 1000000000L
  | GB5   = 5000000000L
  | GB10  = 10000000000L

[<AutoOpen>]
module volLib =
  let libInit = ref false

  let driveList () =
    DriveInfo.GetDrives()

  let freeSpace drive =
    let di = DriveInfo(drive)

  if di.IsReady then int64(di.AvailableFreeSpace)
  else int64(DiskFreeLevels.GB10)

  let cvtBytesToGB (inBytes:int64) =
    truncate((float(int64(inBytes)) / float(1024L) / float(1024L)) / float(1024L))

  let GB1     = cvtBytesToGB(int64(DiskFreeLevels.GB1))
  let GB5     = cvtBytesToGB(int64(DiskFreeLevels.GB5))
  let GB10    = cvtBytesToGB(int64(DiskFreeLevels.GB10))

Advertisements

Leave a comment

Filed under F#