DriveSetLabel

Changes the volume label of the specified drive.

DriveSetLabel Drive , NewLabel

Parameters

Drive

Type: String

The drive letter followed by a colon and an optional backslash (might also work on UNC paths and mapped drives).

On Linux and macOS, specify the volume's mount point instead, such as / or /media/user/BACKUP.

NewLabel

Type: String

If omitted, the drive will have no label. Otherwise, specify the new label to set.

Error Handling

An OSError is thrown on failure, including when the operation is refused for lack of privileges, and on Linux when the volume's filesystem is not one of those listed below.

Platform Remarks

Changing a volume label is a privileged operation on every platform. Expect it to require an elevated process on Windows, and root on Linux and macOS.

Windows

Sets the label directly through the .NET drive API.

Linux

The mount point is resolved to its backing block device with findmnt, then the label is set with the utility for that filesystem: e2label (ext2/ext3/ext4), btrfs filesystem label, xfs_admin, fatlabel (FAT/FAT32/msdos), ntfslabel (NTFS) or exfatlabel. That utility must be installed; any other filesystem throws.

macOS

Renames the volume with diskutil renameVolume.

DriveGetLabel, Drive functions

Examples

Changes the volume label of the C drive.

DriveSetLabel "C:", "Seagate200"