Skip to content

disk Module

Read disk space, usage percentages, and I/O speeds.

javascript
import { disk } from "system";

Availability

Available in the Main script only.

Path Argument Details

For all disk space functions (totalBytes, availableBytes, usedBytes, usagePercent), the path parameter can be:

  • A drive root like "C:\\" or "D:\\"
  • Any file or folder path on the target volume
  • If omitted or empty, defaults to the current working drive

The function determines which volume contains the specified path and returns statistics for that entire volume.

Table of Contents

Methods

disk.totalBytes([path]) #
disk

Returns the total storage capacity of the volume containing the given path.

PARAMETERS

path string OPTIONAL
File or drive path to query (e.g. C:\). Defaults to the current working drive.
RETURNS: number Total capacity of the volume in bytes. Returns 0 if unavailable.
javascript
import { disk } from "system";

const total = disk.totalBytes("C:\\");
console.log("Total:", total, "bytes");
disk.availableBytes([path]) #
disk

Returns the bytes available to the current user on the target volume.

PARAMETERS

path string OPTIONAL
File or drive path to query. Defaults to the current working drive.
RETURNS: number Available bytes for the current user on the target volume. Returns 0 if unavailable.
javascript
import { disk } from "system";

const free = disk.availableBytes("C:\\");
console.log("Free:", free, "bytes");
disk.usedBytes([path]) #
disk

Returns the used storage bytes on the target volume.

PARAMETERS

path string OPTIONAL
File or drive path to query. Defaults to the current working drive.
RETURNS: number Used bytes on the target volume. Returns 0 if unavailable.
javascript
import { disk } from "system";

const used = disk.usedBytes("C:\\");
console.log("Used:", used, "bytes");
disk.usagePercent([path]) #
disk

Returns the disk usage percentage for the target volume.

PARAMETERS

path string OPTIONAL
File or drive path to query. Defaults to the current working drive.
RETURNS: number Usage percentage in the range 0–100. Returns 0 if unavailable.
javascript
import { disk } from "system";

const pct = disk.usagePercent("C:\\");
console.log("Usage:", pct + "%");
disk.readSpeed() #
disk

Returns the current disk read speed sampled from Windows Performance Data Helper (PDH) PhysicalDisk(_Total) counters. The value is cached and updated every 400ms to reduce performance overhead.

Performance Notes

Both readSpeed() and writeSpeed() use the same cached measurement that updates every 400ms. Multiple calls within this window return the same cached value.

RETURNS: number Current disk read throughput in bytes per second. Returns 0 if unavailable.
javascript
import { disk } from "system";

const readBps = disk.readSpeed();
console.log("Read:", readBps, "bytes/sec");
disk.writeSpeed() #
disk

Returns the current disk write speed sampled from Windows Performance Data Helper (PDH) PhysicalDisk(_Total) counters. The value is cached and updated every 400ms to reduce performance overhead.

RETURNS: number Current disk write throughput in bytes per second. Returns 0 if unavailable.
javascript
import { disk } from "system";

const writeBps = disk.writeSpeed();
console.log("Write:", writeBps, "bytes/sec");

Full Example

javascript
import { disk } from "system";

const drive = "C:\\";

console.log("Total:",     disk.totalBytes(drive));
console.log("Available:", disk.availableBytes(drive));
console.log("Used:",      disk.usedBytes(drive));
console.log("Usage %:",   disk.usagePercent(drive));
console.log("Read B/s:",  disk.readSpeed());
console.log("Write B/s:", disk.writeSpeed());