C # obtain disk Information

Source: Internet
Author: User
1, Code Code

System. Io. driveinfo [] Drive = System. Io. driveinfo. getdrives ();
For ( Int I =   0 ; I < Drive. length; I ++ )
{
If (Drive [I]. drivetype = Drivetype. Fixed)
{
Dsmch = Drive [I]. Name;
Double TMP = Drive [I]. totalsize /   1024   /   1024   /   1024   *   100 ;
TMP = Format. Round (TMP, 2 ) /   100 ;
Zhrl = TMP. tostring ();
TMP = Drive [I]. availablefreespace /   1024   /   1024   /   1024   *   100 ;
TMP = Format. Round (TMP, 2 ) /   100 ;
Kyrl = TMP. tostring ();
SQL =   " Insert diskdoc (dsmch, zhrl, kyrl) " ;
SQL + =   " Values (' "   + Dsmch +   " ',' "   + Zhrl +   " ',' "   + Kyrl +   " ') " ;
CMD =   New Sqlcommand (SQL, sqlcon );
Cmd. executenonquery ();
}
}

2. Description

Name: drive letter

Totalfreespace: Return the available disk space. The return value type is long.

drivetype: disk type the returned value is as follows:

CDROM (optical drive) , fixed (Fixed Disk) , unknown (unknown disk) , network (Network Disk) , norootdirectory (the drive letter does not exist) , RAM (Virtual Disk) , removable (removable disk ).

isready : get a value indicating whether the drive is ready return bool type.

rootdirectory : get the root directory of the drive.

totalsize : total space size.

Volumelabel:Returns the string type.

Driveformat: Obtain the name of the file system, such as NTFS or FAT32. 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.