One-day training of Windows APIs (61) getdrivetype Function

Source: Internet
Author: User
One-day training of Windows APIs (61) getdrivetype Function

This requirement is often met. For example, if you need to save a file to a directory, which may be the directory specified by the user, you need to ensure that the directory is valid, in this way, you need to test whether this directory allows file writing? Does this directory exist? Is this Directory Writable? Or is this directory a directory on the network? To complete this task, you must use the getdrivetype function. The getdrivetype function can obtain the Directory and disk number attributes.

The getdrivetype function declaration is as follows:

Winbaseapi
Uint
Winapi
Getdrivetypea (
_ In_opt lpcstr lprootpathname
);
Winbaseapi
Uint
Winapi
Getdrivetypew (
_ In_opt lpcwstr lprootpathname
);
# Ifdef Unicode
# Define getdrivetype getdrivetypew
# Else
# Define getdrivetype getdrivetypea
# Endif //! Unicode

Lprootpathname is the name of the directory or disk number.
The returned value is the directory property, which has the following values:
Drive_unknown
Drive_no_root_dir
Drive_removable
Drive_fixed
Drive_remote
Drive_cdrom
Drive_ramdisk

An example of calling a function is as follows:
#001 // obtain the directory or disk attributes.
#002 // Cai junsheng 2007/10/30 QQ: 9073204 Shenzhen
#003 void disk (void)
#004 {
#005 // obtain the C: Directory attributes.
#006 STD: wstring strtest (_ T ("C: // windows //"));
#007 uint nres =: getdrivetype (strtest. c_str ());
#008 switch (nres)
#009 {
#010 case drive_unknown:
#011 outputdebugstring (_ T ("drive_unknown/R/N "));
#012 break;
#013 case drive_no_root_dir:
#014 outputdebugstring (_ T ("drive_no_root_dir/R/N "));
#015 break;
#016 case drive_removable:
#017 outputdebugstring (_ T ("drive_removable/R/N "));
#018 break;
#019 case drive_fixed:
#020 outputdebugstring (_ T ("drive_fixed/R/N "));
#021 break;
#022 case drive_remote:
#023 outputdebugstring (_ T ("drive_remote/R/N "));
#024 break;
#025 case drive_cdrom:
#026 outputdebugstring (_ T ("drive_cdrom/R/N "));
#027 break;
#028 case drive_ramdisk:
#029 outputdebugstring (_ T ("drive_ramdisk/R/N "));
#030 break;
#031 default:
#032 break;
#033}
#034
#035 // determine whether the drive letter is an optical drive.
#036 strtest = _ T ("D ://");
#037 nres =: getdrivetype (strtest. c_str ());
#038 switch (nres)
#039 {
#040 case drive_unknown:
#041 outputdebugstring (_ T ("drive_unknown/R/N "));
#042 break;
#043 case drive_no_root_dir:
#044 outputdebugstring (_ T ("drive_no_root_dir/R/N "));
#045 break;
#046 case drive_removable:
#047 outputdebugstring (_ T ("drive_removable/R/N "));
#048 break;
#049 case drive_fixed:
#050 outputdebugstring (_ T ("drive_fixed/R/N "));
#051 break;
#052 case drive_remote:
#053 outputdebugstring (_ T ("drive_remote/R/N "));
#054 break;
#055 case drive_cdrom:
#056 outputdebugstring (_ T ("drive_cdrom/R/N "));
#057 break;
#058 case drive_ramdisk:
#059 outputdebugstring (_ T ("drive_ramdisk/R/N "));
#060 break;
#061 default:
#062 break;
#063}
#064}

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.