How do I get information from the drives by c#?

Asked

Viewed 68 times

0

Good afternoon, I was asked to carry out a project that can fetch information from drives (C:, D:, etc), such as how many drives there are, the name of each one, the total space and the used.

But I don’t know how I can get that information. Can anyone help me?

  • You speak of Windows drives?

1 answer

4


You can use the class Driveinfo to get information from drives.

static void Main(string[] args)
{
    var drives = DriveInfo.GetDrives();
    foreach (DriveInfo info in drives)
    {
          Console.WriteLine("Nome: {0}\nTamanho: {1}\nTipo de particao: {2}", info.Name, info.TotalSize, info.DriveFormat);
    }
     Console.ReadLine();
}
  • Thank you so much!!

  • Would not be drives, without the R?

  • 1

    @Marcelouchimura thanks. Already corrected.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.