xtd 0.2.0
Loading...
Searching...
No Matches
xtd::io::drive_info Class Reference
Inheritance diagram for xtd::io::drive_info:
xtd::object

Definition

Provides access to information on a drive.

Provides access to information on a drive.
Definition drive_info.hpp:33
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:42
#define core_export_
Define shared library export.
Definition core_export.hpp:13
Inheritance
xtd::objectxtd::io::drive_info
Header
#include <xtd/io/drive_info>
Namespace
xtd::io
Library
xtd.core
Examples
The following code example demonstrates the use of the xtd::io::drive_info class to display information about all of the drives on the current system.
#include <xtd/io/drive_info>
#include <xtd/console>
#include <xtd/startup>
using namespace xtd;
using namespace xtd::io;
class program {
public:
static auto main() {
auto all_drives = drive_info::get_drives();
for (auto d : all_drives) {
console::write_line("Drive {0}", d.name());
console::write_line(" Drive type: {0}", d.drive_type());
if (d.is_ready() == true) {
console::write_line(" Volume label: {0}", d.volume_label());
console::write_line(" File system: {0}", d.drive_format());
console::write_line(" Available space to current user:{0, 15} bytes", d.available_free_space());
console::write_line(" Total available space: {0, 15} bytes", d.total_free_space());
console::write_line(" Total size of drive: {0, 15} bytes", d.total_size());
}
}
}
};
startup_(program::main);
// This code produces the following output :
//
// Drive A:\
// Drive type: Removable
// Drive C:\
// Drive type: Fixed
// Volume label:
// File system: FAT32
// Available space to current user: 4770430976 bytes
// Total available space: 4770430976 bytes
// Total size of drive: 10731683840 bytes
// Drive D:\
// Drive type: Fixed
// Volume label:
// File system: NTFS
// Available space to current user: 15114977280 bytes
// Total available space: 15114977280 bytes
// Total size of drive: 25958948864 bytes
// Drive E:\
// Drive type: CDRom
//
// The actual output of this code will vary based on machine and the permissions
// granted to the user executing it.
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:175
@ d
The D key.
The xtd::io namespace contains types that allow reading and writing to files and data streams,...
Definition binary_reader.hpp:16
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Remarks
This class models a drive and provides methods and properties to query for drive information. Use xtd::io::drive_info to determine what drives are available, and what type of drives they are. You can also query to determine the capacity and available free space on the drive.

Public Fields

static const drive_info empty
 Represents the uninitialized xtd::io::drive_info object. This field is constant.
 

Public Constructors

 drive_info (const xtd::string &drive_name)
 Provides access to information on the specified drive.
 

Public Properties

size_t available_free_space () const
 Indicates the amount of available free space on a drive, in bytes.
 
xtd::string drive_format () const
 Gets the name of the file system, such as NTFS or FAT32.
 
xtd::io::drive_type drive_type () const
 Gets the drive type, such as CD-ROM, removable, network, or fixed.
 
bool is_ready () const noexcept
 Gets a value that indicates whether a drive is ready.
 
xtd::string name () const noexcept
 Gets the name of a drive, such as C:.
 
xtd::io::directory_info root_directory () const noexcept
 Gets the root directory of a drive.
 
size_t total_free_space () const
 Gets the total amount of free space available on a drive, in bytes.
 
size_t total_size () const
 Gets the total size of storage space on a drive, in bytes.
 
xtd::string volume_label () const
 Gets the volume label of a drive.
 

Public Methods

xtd::string to_string () const noexcept override
 Returns a drive name as a string.
 

Public Static Methods

static std::vector< xtd::io::drive_infoget_drives () noexcept
 Retrieves the drive names of all logical drives on a computer.
 

Additional Inherited Members

- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<typename object_t >
xtd::uptr< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
- Static Public Member Functions inherited from xtd::object
template<typename object_a_t , typename object_b_t >
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
template<typename object_a_t , typename object_b_t >
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 

Constructor & Destructor Documentation

◆ drive_info()

xtd::io::drive_info::drive_info ( const xtd::string drive_name)
explicit

Provides access to information on the specified drive.

Parameters
drive_nameA valid drive path or drive letter. This can be either uppercase or lowercase, 'a' to 'z'. A null value is not valid.
Exceptions
xtd::argument_exceptiondrive_name does not refer to a valid drive.
Remarks
Use this class to obtain information on drives. The drive name must be either an uppercase or lowercase letter from 'a' to 'z'. You cannot use this method to obtain information on drive names that are null or use UNC (\server\share) paths.

Member Function Documentation

◆ available_free_space()

size_t xtd::io::drive_info::available_free_space ( ) const

Indicates the amount of available free space on a drive, in bytes.

Returns
The amount of free space available on the drive, in bytes.
Exceptions
xtd::unauthorized_access_exceptionAccess to the drive information is denied.
xtd::io::drive_not_foundThe drive does not exist or is not mapped.
xtd::io::io_exceptionAn I/O error occurred (for example, a disk error or a drive was not ready).
Examples
The following code example demonstrates the use of the xtd::io::drive_info class to display information about all of the drives on the current system.
#include <xtd/io/drive_info>
#include <xtd/console>
#include <xtd/startup>
using namespace xtd;
using namespace xtd::io;
class program {
public:
static auto main() {
auto all_drives = drive_info::get_drives();
for (auto d : all_drives) {
console::write_line("Drive {0}", d.name());
console::write_line(" Drive type: {0}", d.drive_type());
if (d.is_ready() == true) {
console::write_line(" Volume label: {0}", d.volume_label());
console::write_line(" File system: {0}", d.drive_format());
console::write_line(" Available space to current user:{0, 15} bytes", d.available_free_space());
console::write_line(" Total available space: {0, 15} bytes", d.total_free_space());
console::write_line(" Total size of drive: {0, 15} bytes", d.total_size());
}
}
}
};
startup_(program::main);
// This code produces the following output :
//
// Drive A:\
// Drive type: Removable
// Drive C:\
// Drive type: Fixed
// Volume label:
// File system: FAT32
// Available space to current user: 4770430976 bytes
// Total available space: 4770430976 bytes
// Total size of drive: 10731683840 bytes
// Drive D:\
// Drive type: Fixed
// Volume label:
// File system: NTFS
// Available space to current user: 15114977280 bytes
// Total available space: 15114977280 bytes
// Total size of drive: 25958948864 bytes
// Drive E:\
// Drive type: CDRom
//
// The actual output of this code will vary based on machine and the permissions
// granted to the user executing it.
Remarks
This property indicates the amount of free space available on the drive. Note that this number may be different from the xtd::io::drive_info::total_free_space number because this property takes into account disk quotas.

◆ drive_format()

xtd::string xtd::io::drive_info::drive_format ( ) const

Gets the name of the file system, such as NTFS or FAT32.

Returns
The name of the file system on the specified drive.
Exceptions
xtd::unauthorized_access_exceptionAccess to the drive information is denied.
xtd::io::drive_not_foundThe drive does not exist or is not mapped.
xtd::io::io_exceptionAn I/O error occurred (for example, a disk error or a drive was not ready).
Examples
The following code example demonstrates the use of the xtd::io::drive_info class to display information about all of the drives on the current system.
#include <xtd/io/drive_info>
#include <xtd/console>
#include <xtd/startup>
using namespace xtd;
using namespace xtd::io;
class program {
public:
static auto main() {
auto all_drives = drive_info::get_drives();
for (auto d : all_drives) {
console::write_line("Drive {0}", d.name());
console::write_line(" Drive type: {0}", d.drive_type());
if (d.is_ready() == true) {
console::write_line(" Volume label: {0}", d.volume_label());
console::write_line(" File system: {0}", d.drive_format());
console::write_line(" Available space to current user:{0, 15} bytes", d.available_free_space());
console::write_line(" Total available space: {0, 15} bytes", d.total_free_space());
console::write_line(" Total size of drive: {0, 15} bytes", d.total_size());
}
}
}
};
startup_(program::main);
// This code produces the following output :
//
// Drive A:\
// Drive type: Removable
// Drive C:\
// Drive type: Fixed
// Volume label:
// File system: FAT32
// Available space to current user: 4770430976 bytes
// Total available space: 4770430976 bytes
// Total size of drive: 10731683840 bytes
// Drive D:\
// Drive type: Fixed
// Volume label:
// File system: NTFS
// Available space to current user: 15114977280 bytes
// Total available space: 15114977280 bytes
// Total size of drive: 25958948864 bytes
// Drive E:\
// Drive type: CDRom
//
// The actual output of this code will vary based on machine and the permissions
// granted to the user executing it.
Remarks
Use xtd::io::drive_info::drive_format to determine what formatting a drive uses.

◆ drive_type()

xtd::io::drive_type xtd::io::drive_info::drive_type ( ) const

Gets the drive type, such as CD-ROM, removable, network, or fixed.

Returns
One of the enumeration values that specifies a drive type.
Examples
The following code example demonstrates the use of the xtd::io::drive_info class to display information about all of the drives on the current system.
#include <xtd/io/drive_info>
#include <xtd/console>
#include <xtd/startup>
using namespace xtd;
using namespace xtd::io;
class program {
public:
static auto main() {
auto all_drives = drive_info::get_drives();
for (auto d : all_drives) {
console::write_line("Drive {0}", d.name());
console::write_line(" Drive type: {0}", d.drive_type());
if (d.is_ready() == true) {
console::write_line(" Volume label: {0}", d.volume_label());
console::write_line(" File system: {0}", d.drive_format());
console::write_line(" Available space to current user:{0, 15} bytes", d.available_free_space());
console::write_line(" Total available space: {0, 15} bytes", d.total_free_space());
console::write_line(" Total size of drive: {0, 15} bytes", d.total_size());
}
}
}
};
startup_(program::main);
// This code produces the following output :
//
// Drive A:\
// Drive type: Removable
// Drive C:\
// Drive type: Fixed
// Volume label:
// File system: FAT32
// Available space to current user: 4770430976 bytes
// Total available space: 4770430976 bytes
// Total size of drive: 10731683840 bytes
// Drive D:\
// Drive type: Fixed
// Volume label:
// File system: NTFS
// Available space to current user: 15114977280 bytes
// Total available space: 15114977280 bytes
// Total size of drive: 25958948864 bytes
// Drive E:\
// Drive type: CDRom
//
// The actual output of this code will vary based on machine and the permissions
// granted to the user executing it.
Remarks
The xtd::io::drive_info::drive_type property indicates whether a drive is one of the following: CDRom, Fixed, Network, NoRootDirectory, Ram, Removable, or Unknown. These values are described in the xtd::io::drive_type enumeration.

◆ is_ready()

bool xtd::io::drive_info::is_ready ( ) const
noexcept

Gets a value that indicates whether a drive is ready.

Returns
true if the drive is ready; false if the drive is not ready.
Examples
The following code example demonstrates the use of the xtd::io::drive_info class to display information about all of the drives on the current system.
#include <xtd/io/drive_info>
#include <xtd/console>
#include <xtd/startup>
using namespace xtd;
using namespace xtd::io;
class program {
public:
static auto main() {
auto all_drives = drive_info::get_drives();
for (auto d : all_drives) {
console::write_line("Drive {0}", d.name());
console::write_line(" Drive type: {0}", d.drive_type());
if (d.is_ready() == true) {
console::write_line(" Volume label: {0}", d.volume_label());
console::write_line(" File system: {0}", d.drive_format());
console::write_line(" Available space to current user:{0, 15} bytes", d.available_free_space());
console::write_line(" Total available space: {0, 15} bytes", d.total_free_space());
console::write_line(" Total size of drive: {0, 15} bytes", d.total_size());
}
}
}
};
startup_(program::main);
// This code produces the following output :
//
// Drive A:\
// Drive type: Removable
// Drive C:\
// Drive type: Fixed
// Volume label:
// File system: FAT32
// Available space to current user: 4770430976 bytes
// Total available space: 4770430976 bytes
// Total size of drive: 10731683840 bytes
// Drive D:\
// Drive type: Fixed
// Volume label:
// File system: NTFS
// Available space to current user: 15114977280 bytes
// Total available space: 15114977280 bytes
// Total size of drive: 25958948864 bytes
// Drive E:\
// Drive type: CDRom
//
// The actual output of this code will vary based on machine and the permissions
// granted to the user executing it.
Remarks
xtd::io::drive_info::is_ready indicates whether a drive is ready. For example, it indicates whether a CD is in a CD drive or whether a removable storage device is ready for read/write operations. If you do not test whether a drive is ready, and it is not ready, querying the drive using xtd::io::drive_info will raise an xtd::io::io_exception.
Do not rely on xtd::io::drive_info::is_ready to avoid catching exceptions from other members such as xtd::io::drive_info::total_size, xtd::io::drive_info::total_free_space, and xtd::io::drive_info::drive_format. Between the time that your code checks xtd::io::drive_info::is_ready and then accesses one of the other properties (even if the access occurs immediately after the check), a drive may have been disconnected or a disk may have been removed.

◆ name()

xtd::string xtd::io::drive_info::name ( ) const
noexcept

Gets the name of a drive, such as C:.

Returns
The name of the drive.
Examples
The following code example demonstrates the use of the xtd::io::drive_info class to display information about all of the drives on the current system.
#include <xtd/io/drive_info>
#include <xtd/console>
#include <xtd/startup>
using namespace xtd;
using namespace xtd::io;
class program {
public:
static auto main() {
auto all_drives = drive_info::get_drives();
for (auto d : all_drives) {
console::write_line("Drive {0}", d.name());
console::write_line(" Drive type: {0}", d.drive_type());
if (d.is_ready() == true) {
console::write_line(" Volume label: {0}", d.volume_label());
console::write_line(" File system: {0}", d.drive_format());
console::write_line(" Available space to current user:{0, 15} bytes", d.available_free_space());
console::write_line(" Total available space: {0, 15} bytes", d.total_free_space());
console::write_line(" Total size of drive: {0, 15} bytes", d.total_size());
}
}
}
};
startup_(program::main);
// This code produces the following output :
//
// Drive A:\
// Drive type: Removable
// Drive C:\
// Drive type: Fixed
// Volume label:
// File system: FAT32
// Available space to current user: 4770430976 bytes
// Total available space: 4770430976 bytes
// Total size of drive: 10731683840 bytes
// Drive D:\
// Drive type: Fixed
// Volume label:
// File system: NTFS
// Available space to current user: 15114977280 bytes
// Total available space: 15114977280 bytes
// Total size of drive: 25958948864 bytes
// Drive E:\
// Drive type: CDRom
//
// The actual output of this code will vary based on machine and the permissions
// granted to the user executing it.
Remarks
This property is the name assigned to the drive, such as C:\ or E:.

◆ root_directory()

xtd::io::directory_info xtd::io::drive_info::root_directory ( ) const
noexcept

Gets the root directory of a drive.

Returns
An object that contains the root directory of the drive.

◆ total_free_space()

size_t xtd::io::drive_info::total_free_space ( ) const

Gets the total amount of free space available on a drive, in bytes.

Returns
The total free space available on a drive, in bytes.
Exceptions
xtd::unauthorized_access_exceptionAccess to the drive information is denied.
xtd::io::drive_not_foundThe drive does not exist or is not mapped.
xtd::io::io_exceptionAn I/O error occurred (for example, a disk error or a drive was not ready).
Examples
The following code example demonstrates the use of the xtd::io::drive_info class to display information about all of the drives on the current system.
#include <xtd/io/drive_info>
#include <xtd/console>
#include <xtd/startup>
using namespace xtd;
using namespace xtd::io;
class program {
public:
static auto main() {
auto all_drives = drive_info::get_drives();
for (auto d : all_drives) {
console::write_line("Drive {0}", d.name());
console::write_line(" Drive type: {0}", d.drive_type());
if (d.is_ready() == true) {
console::write_line(" Volume label: {0}", d.volume_label());
console::write_line(" File system: {0}", d.drive_format());
console::write_line(" Available space to current user:{0, 15} bytes", d.available_free_space());
console::write_line(" Total available space: {0, 15} bytes", d.total_free_space());
console::write_line(" Total size of drive: {0, 15} bytes", d.total_size());
}
}
}
};
startup_(program::main);
// This code produces the following output :
//
// Drive A:\
// Drive type: Removable
// Drive C:\
// Drive type: Fixed
// Volume label:
// File system: FAT32
// Available space to current user: 4770430976 bytes
// Total available space: 4770430976 bytes
// Total size of drive: 10731683840 bytes
// Drive D:\
// Drive type: Fixed
// Volume label:
// File system: NTFS
// Available space to current user: 15114977280 bytes
// Total available space: 15114977280 bytes
// Total size of drive: 25958948864 bytes
// Drive E:\
// Drive type: CDRom
//
// The actual output of this code will vary based on machine and the permissions
// granted to the user executing it.
Remarks
This property indicates the total amount of free space available on the drive, not just what is available to the current user.

◆ total_size()

size_t xtd::io::drive_info::total_size ( ) const

Gets the total size of storage space on a drive, in bytes.

Returns
The total size of the drive, in bytes.
Exceptions
xtd::unauthorized_access_exceptionAccess to the drive information is denied.
xtd::io::drive_not_foundThe drive does not exist or is not mapped.
xtd::io::io_exceptionAn I/O error occurred (for example, a disk error or a drive was not ready).
Examples
The following code example demonstrates the use of the xtd::io::drive_info class to display information about all of the drives on the current system.
#include <xtd/io/drive_info>
#include <xtd/console>
#include <xtd/startup>
using namespace xtd;
using namespace xtd::io;
class program {
public:
static auto main() {
auto all_drives = drive_info::get_drives();
for (auto d : all_drives) {
console::write_line("Drive {0}", d.name());
console::write_line(" Drive type: {0}", d.drive_type());
if (d.is_ready() == true) {
console::write_line(" Volume label: {0}", d.volume_label());
console::write_line(" File system: {0}", d.drive_format());
console::write_line(" Available space to current user:{0, 15} bytes", d.available_free_space());
console::write_line(" Total available space: {0, 15} bytes", d.total_free_space());
console::write_line(" Total size of drive: {0, 15} bytes", d.total_size());
}
}
}
};
startup_(program::main);
// This code produces the following output :
//
// Drive A:\
// Drive type: Removable
// Drive C:\
// Drive type: Fixed
// Volume label:
// File system: FAT32
// Available space to current user: 4770430976 bytes
// Total available space: 4770430976 bytes
// Total size of drive: 10731683840 bytes
// Drive D:\
// Drive type: Fixed
// Volume label:
// File system: NTFS
// Available space to current user: 15114977280 bytes
// Total available space: 15114977280 bytes
// Total size of drive: 25958948864 bytes
// Drive E:\
// Drive type: CDRom
//
// The actual output of this code will vary based on machine and the permissions
// granted to the user executing it.
Remarks
This property indicates the total size of the drive in bytes, not just what is available to the current user.

◆ volume_label()

xtd::string xtd::io::drive_info::volume_label ( ) const

Gets the volume label of a drive.

Returns
The volume label.
Exceptions
xtd::unauthorized_access_exceptionAccess to the drive information is denied.
xtd::io::drive_not_foundThe drive does not exist or is not mapped.
xtd::io::io_exceptionAn I/O error occurred (for example, a disk error or a drive was not ready).
Examples
The following code example demonstrates the use of the xtd::io::drive_info class to display information about all of the drives on the current system.
#include <xtd/io/drive_info>
#include <xtd/console>
#include <xtd/startup>
using namespace xtd;
using namespace xtd::io;
class program {
public:
static auto main() {
auto all_drives = drive_info::get_drives();
for (auto d : all_drives) {
console::write_line("Drive {0}", d.name());
console::write_line(" Drive type: {0}", d.drive_type());
if (d.is_ready() == true) {
console::write_line(" Volume label: {0}", d.volume_label());
console::write_line(" File system: {0}", d.drive_format());
console::write_line(" Available space to current user:{0, 15} bytes", d.available_free_space());
console::write_line(" Total available space: {0, 15} bytes", d.total_free_space());
console::write_line(" Total size of drive: {0, 15} bytes", d.total_size());
}
}
}
};
startup_(program::main);
// This code produces the following output :
//
// Drive A:\
// Drive type: Removable
// Drive C:\
// Drive type: Fixed
// Volume label:
// File system: FAT32
// Available space to current user: 4770430976 bytes
// Total available space: 4770430976 bytes
// Total size of drive: 10731683840 bytes
// Drive D:\
// Drive type: Fixed
// Volume label:
// File system: NTFS
// Available space to current user: 15114977280 bytes
// Total available space: 15114977280 bytes
// Total size of drive: 25958948864 bytes
// Drive E:\
// Drive type: CDRom
//
// The actual output of this code will vary based on machine and the permissions
// granted to the user executing it.
Remarks
The label length is determined by the operating system. For example, NTFS allows a volume label to be up to 32 characters long.

◆ to_string()

xtd::string xtd::io::drive_info::to_string ( ) const
overridevirtualnoexcept

Returns a drive name as a string.

Returns
The name of the drive.
Remarks
This method returns the xtd::io::drive_info::name property.

Reimplemented from xtd::object.

◆ get_drives()

static std::vector< xtd::io::drive_info > xtd::io::drive_info::get_drives ( )
staticnoexcept

Retrieves the drive names of all logical drives on a computer.

Returns
An array of type xtd::ioo::drive_info that represents the logical drives on a computer.
Exceptions
xtd::unauthorized_access_exceptionAccess to the drive information is denied.
xtd::io::io_exceptionAn I/O error occurred (for example, a disk error or a drive was not ready).
Examples
The following code example demonstrates the use of the xtd::io::drive_info class to display information about all of the drives on the current system.
#include <xtd/io/drive_info>
#include <xtd/console>
#include <xtd/startup>
using namespace xtd;
using namespace xtd::io;
class program {
public:
static auto main() {
auto all_drives = drive_info::get_drives();
for (auto d : all_drives) {
console::write_line("Drive {0}", d.name());
console::write_line(" Drive type: {0}", d.drive_type());
if (d.is_ready() == true) {
console::write_line(" Volume label: {0}", d.volume_label());
console::write_line(" File system: {0}", d.drive_format());
console::write_line(" Available space to current user:{0, 15} bytes", d.available_free_space());
console::write_line(" Total available space: {0, 15} bytes", d.total_free_space());
console::write_line(" Total size of drive: {0, 15} bytes", d.total_size());
}
}
}
};
startup_(program::main);
// This code produces the following output :
//
// Drive A:\
// Drive type: Removable
// Drive C:\
// Drive type: Fixed
// Volume label:
// File system: FAT32
// Available space to current user: 4770430976 bytes
// Total available space: 4770430976 bytes
// Total size of drive: 10731683840 bytes
// Drive D:\
// Drive type: Fixed
// Volume label:
// File system: NTFS
// Available space to current user: 15114977280 bytes
// Total available space: 15114977280 bytes
// Total size of drive: 25958948864 bytes
// Drive E:\
// Drive type: CDRom
//
// The actual output of this code will vary based on machine and the permissions
// granted to the user executing it.
Remarks
This method retrieves all logical drive names on a computer. You can use this information to iterate through the array and obtain information on the drives using other xtd::io::drive_info methods and properties. Use the xtd::io::drive_info::is_ready property to test whether a drive is ready because using this method on a drive that is not ready will throw a xtd::io::io_exception.

Member Data Documentation

◆ empty

const drive_info xtd::io::drive_info::empty
static

Represents the uninitialized xtd::io::drive_info object. This field is constant.


The documentation for this class was generated from the following file: