GetLogicalDrives Method

Directory.GetLogicalDrives Method ()


Retrieves the names of the logical drives on this computer in the form "<drive letter>:\".

Namespace:   System.IO
Assembly:  mscorlib (in mscorlib.dll)

public static string[] GetLogicalDrives()

Return Value

Type: System.String[]

The logical drives on this computer.

Exception Condition

An I/O error occured (for example, a disk error).


The caller does not have the required permission.

GetLogicalDrives returns all of the accessible drives on a particular machine, including the floppy drive and any optical drives.

For a list of common I/O tasks, see Common I/O Tasks.

The following example uses the GetLogicalDrives method to assign the name of each drive on the calling computer to an array of strings. Each member of this string array is then printed to the console. The example is configured to catch all errors common to this method.

Snippet section 3 of code snippet {"project_id":"3fedad16-eaf1-41a6-8f96-0c1949c68f32","entity_id":"caa9851d-1f4b-4024-9302-cca596bd8277","entity_type":"CodeSnippet","locale":"en-US"} in source file ({"filename":"/CS/class1.cs","blob_type":"Source","blob_id":"-002fcs-002fclass1-002ecs","blob_revision":2}) overlaps with other snippet sections. Ensure the tags are placed correctly.

for calling unmanaged code, such as calling native code with PInvoke or COM interop. Associated enumeration: SecurityPermissionFlag.UnmanagedCode

.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft