遍歷磁碟資訊

2021-07-04 21:16:08 字數 2478 閱讀 4834

//.h

#pragmaonce

#include

#include

usingstd::list;

typedefstruct_drive_info

storage_info;

}drive_info,*pdrive_info;

classcdiskcontrol ;

//.cpp

#include"diskcontrol.h"

cdiskcontrol::cdiskcontrol(void);

getlogicaldrivestrings(max_path,szpathname

);for

(int

i=0;

szpathname[i]!='\0'

&&i; i++ )}

cdiskcontrol::~

cdiskcontrol(void)

boolcdiskcontrol::getdirverinfo(

lpctstrszname);

// 1. 儲存驅動器名稱

wcscpy_s(stcinfo.szname,szname);

// 2. 儲存驅動器型別

stcinfo.udrivetype

=getdrivetype(szname);

// 3. 儲存驅動器描述資訊

switch

(stcinfo.udrivetype)

case

drive_ramdisk:

wcscpy_s(stcinfo.szdrivetypedescription,

l"ram驅動器");

break;

default:

wcscpy_s(stcinfo.szdrivetypedescription,

l"驅動器型別錯誤");

break; }

// 4. 獲取並儲存驅動器的卷系列號、檔名最大長度、檔案系統標記、檔案系統名稱資訊

getvolumeinformation(

stcinfo.szname,

// 碟符/驅動器名

stcinfo.szdrivetitle,

// 驅動器標題

max_path,

// 標題名陣列最大空間

&stcinfo.dwvolumeserialid,

// 驅動器的卷系列號

&stcinfo.dwmaxcomponentlen,

// 檔名最大長度

&stcinfo.dwfilesystemflags,

// 檔案系統標記

stcinfo.szfilesystemname,

// 檔案系統名

max_path);

// 檔案系統名陣列最大空間

// 5. 使用getdiskfreespace獲取磁碟資訊並列印結果

getdiskfreespace

(szname,

// 碟符/驅動器名

&stcinfo.storage_info.dwsectperclust,

// 每簇的扇區數量

&stcinfo.storage_info.dwbytespersect,

// 每個扇區的位元組數

&stcinfo.storage_info.dwfreeclusters,

// 空閒簇的總數

&stcinfo.storage_info.dwtotalclusters)

;// 全部簇的總數

stcinfo.storage_info.qwtotalbytes

=(dword64

)stcinfo.storage_info.dwtotalclusters

/* 全部簇的總數 */

*(dword64

)stcinfo.storage_info.dwsectperclust

/* 每簇的扇區數量 */

*(dword64

)stcinfo.storage_info.dwbytespersect;

/* 每個扇區的容量 */

stcinfo.storage_info.qwfreebytes

=(dword64

)stcinfo.storage_info.dwfreeclusters

/* 空閒簇的總數 */

*(dword64

)stcinfo.storage_info.dwsectperclust

/* 每簇的扇區數量 */

*(dword64

)stcinfo.storage_info.dwbytespersect;

/* 每個扇區的容量 */

// 6. 儲存此資訊

m_lstdriveinfo.push_back(

stcinfo);

return

true;}

list*cdiskcontrol

::getdriveinfolist()

檢視磁碟資訊磁碟空間

如果要檢視磁碟還剩多少空間,當然是用df的命令了。root localhost df h 檔案系統 容量 已用 可用 已用 掛載點 dev sda2 14g 11g 2.6g 82 dev sda1 99m 14m 81m 14 boot tmpfs 442m 275m 168m 63 dev sh...

遍歷本機磁碟

using system using system.collections.generic using system.collections using system.text using system.io namespace bainli public arraylist getfilename...

fdisk 檢視磁碟資訊

fdisk 檢視磁碟資訊 fdisk l dev to some device file fdisk l 可以列出當前系統所有磁碟以及磁碟分割槽 管理磁碟分割槽 fdisk dev sda 可以開啟互動式介面 子命令 m 檢視幫助 p 顯示當前硬體的分割槽,包括沒儲存的改動 n 建立新分割槽 e 表...