Loading... ![image.png](http://www.irohane.top/usr/uploads/2020/12/3128132547.png) | DRIVE_REMOVABLE | 可移动设备 | | - | - | | DRIVE_FIXED | 硬盘 | | DRIVE_REMOTE | 远程设备 | | DRIVE_CDROM | 光驱 | | | | ```cpp #include <iostream> #include <Windows.h> #include <tchar.h> int main() { //1. 获取驱动器名称 TCHAR buf[100] = {}; TCHAR* pTemp = buf; GetLogicalDriveStrings( 100,buf); // 把语言设置为中文 setlocale(LC_ALL, "chs"); while (pTemp[0]!=0) { wprintf(_T("%s "), pTemp); //2. 获取驱动器类型 DWORD dwType = GetDriveType(pTemp); switch (dwType) { case DRIVE_REMOVABLE: wprintf(_T("可移动设备 ")); break; case DRIVE_FIXED: wprintf(_T("硬盘 ")); break; case DRIVE_REMOTE: wprintf(_T("远程设备 ")); break; case DRIVE_CDROM: wprintf(_T("光驱 ")); break; default: break; } //3. 驱动器的空间信息 DWORD 每簇的扇区数量 = 0; DWORD 每个扇区的容量 = 0; DWORD 空闲簇的总量 = 0; DWORD 全部簇的总量 = 0; GetDiskFreeSpace(pTemp, &每簇的扇区数量, &每个扇区的容量, &空闲簇的总量, &全部簇的总量 ); printf("总容量为%.2lf,空闲容量为%.2lf", (((全部簇的总量/1024.0) * 每簇的扇区数量 * 每个扇区的容量)/1024)/1024, (((空闲簇的总量/1024.0) * 每簇的扇区数量 * 每个扇区的容量) / 1024) / 1024); printf("\n"); pTemp += wcslen(buf)+1; } } ``` ## 文件操作-API kernel32.dll 系统基本的API函数,创建文件,线程 User32.dll widnows图形用户支持,创建控件 GDI32.dll 包含了GDI相关接口,画线,划点 | GetLogicalDriveString(存储的数组,TCHAR* 指针) | 获取驱动器名称 | | - | - | | setlocale(LC_ALL,"chs") | 设置语言为中文 | | | | | | | | DeleteFile | 删除文件 | | - | - | | CopyFile | 拷贝文件 | | MoveFile | 移动文件 | | CreateFile | 创建文件/并获取句柄 | | ReadFile | 读取文件句柄所指定的文件内容 | | WriteFile | 向文件句柄所指定的文件写入数据 | | GetFileSize/Ex | 获取文件大小/获取文件大小存入64位大小联合体中 | | CreateDirectory | 创建一个目录 | | GetModuleFileName | 获取当前模块的全路径 | | FindFirstFile | 查找指定第一个文件/目录,并获取句柄 | | FindNextFile | 根据文件句柄循环查找其他文件目录 | | GetFileAttributes | 获取文件属性 | | GetFileAttributesEx | 设置文件或者目录属性 | | FileTimeToLocalFile | 将文件时间转换为本地时间 | | FileTimeToSystemTime | 文件时间转换为本地时间 | | | | | | | | | | 最后修改:2021 年 03 月 01 日 © 允许规范转载 赞 0 如果觉得我的文章对你有用,请随意赞赏
1 条评论
叼茂SEO.bfbikes.com