VC obtains the disk space (total, used, and remaining)

Source: Internet
Author: User

Cstring curdiskno; // the disk symbol of the current video.
Cstring totaldisksize; // The total size of the current ephemeral Disk
Cstring freedisksize; // The current video disk and remaining space

Char cname [4 * m_imaxcount] = {0 };
Char sdiskpath [4 * m_imaxcount] = {0 };
Getmodulefilename (null, cname, sizeof (cname); // get the current runProgramPath
Cstring ssettingfile;
Ssettingfile. Format ("% s", cname );
Ssettingfile = ssettingfile. Left (ssettingfile. reversefind ('//'));
Ssettingfile = ssettingfile + "//" + "setting. ini ";

// Obtain the full path of the configuration file. The drive letter of the portable disk is saved in setting. ini.
Getprivateprofilestring ("disk", "path", null, sdiskpath, sizeof (sdiskpath), ssettingfile );

// Obtain the drive letter from the configuration file
Char diskname [4];
Diskname [0] = sdiskpath [0];
Diskname [1] = sdiskpath [1];
Diskname [2] = sdiskpath [2];
Diskname [3] = '/0 ';
Ularge_integer lpuse;
Ularge_integer lptotal;
Ularge_integer lpfree;
Getdiskfreespaceex (diskname, & lpuse, & lptotal, & lpfree );

// Obtain the total capacity, used space, and remaining space of the diskname drive.
Totaldisksize. Format ("total space: % 4.2fgb", lptotal. quadpart/1024.0/1024.0/1024.0 );
Freedisksize. Format ("available space: % 4.2fgb", lpfree. quadpart/1024.0/1024.0/1024.0 );
Curdiskno. Format ("Current Disk: % s", sdiskpath );

 

 

 

The content of the Setting. ini file is as follows:

 

[Package]
Time = 1
[Disk]
Path = E :/

 

Then the diskname above is E: // get the space size of the E disk. Here, the setting. ini file is placed in the directory of the execution file.

 

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.