disk Module
Read disk space, usage percentages, and I/O speeds.
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
Returns the total storage capacity of the volume containing the given path.
PARAMETERS
number Total capacity of the volume in bytes. Returns 0 if unavailable.import { disk } from "system";
const total = disk.totalBytes("C:\\");
console.log("Total:", total, "bytes");Returns the bytes available to the current user on the target volume.
PARAMETERS
number Available bytes for the current user on the target volume. Returns 0 if unavailable.import { disk } from "system";
const free = disk.availableBytes("C:\\");
console.log("Free:", free, "bytes");Returns the used storage bytes on the target volume.
PARAMETERS
number Used bytes on the target volume. Returns 0 if unavailable.import { disk } from "system";
const used = disk.usedBytes("C:\\");
console.log("Used:", used, "bytes");Returns the disk usage percentage for the target volume.
PARAMETERS
number Usage percentage in the range 0–100. Returns 0 if unavailable.import { disk } from "system";
const pct = disk.usagePercent("C:\\");
console.log("Usage:", pct + "%");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.
number Current disk read throughput in bytes per second. Returns 0 if unavailable.import { disk } from "system";
const readBps = disk.readSpeed();
console.log("Read:", readBps, "bytes/sec");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.
number Current disk write throughput in bytes per second. Returns 0 if unavailable.import { disk } from "system";
const writeBps = disk.writeSpeed();
console.log("Write:", writeBps, "bytes/sec");Full Example
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());