17-10-12, 05:41 PM
كاتب الموضوع : AhmedEssawy
لمعرفه المساحه الخاليه بالبايت byte علي قرص معين (هارد ديسك معين) بالاعتماد علي ال A
كود :
[align=left][FONT=Courier New][[color=teal]DllImport[/color]( [color=maroon]"kernel32.dll"[/color], EntryPoint=[color=maroon]"GetDiskFreeSpaceExA"[/color] )][/FONT]
[FONT=Courier New][[color=teal]CLSCompliant[/color]([color=blue]false[/color])][/FONT]
[FONT=Courier New][color=blue]public[/color] [color=blue]static[/color] [color=blue]extern[/color] [color=blue]int[/color] GetDiskFreeSpaceEx([color=blue]string[/color] lpRootPathName,[/FONT]
[FONT=Courier New][color=blue]ref[/color] [color=blue]int[/color] lpFreeBytesAvailableToCaller,[/FONT]
[FONT=Courier New][color=blue]ref[/color] [color=blue]int[/color] lpTotalNumberOfBytes,[/FONT]
[FONT=Courier New][color=blue]ref[/color] [color=teal]UInt32[/color] lpTotalNumberOfFreeBytes);[/FONT]
[color=green][FONT=Courier New]// This gets the number of free bytes on a disk, by Win32 API call GetDiskFreeSpaceEx[/FONT][/color]
[FONT=Courier New][color=blue]private[/color] [color=blue]void[/color] btnGetDiskFreeSpaceEx_Click([color=blue]object[/color] sender, System.[color=teal]EventArgs[/color] e) [/FONT]
[FONT=Courier New]{[/FONT]
[FONT=Courier New][color=blue]string[/color] rootPathName = [color=maroon]""[/color];[/FONT]
[FONT=Courier New][color=blue]int[/color] freeBytesToCaller = 0;[/FONT]
[FONT=Courier New][color=blue]int[/color] totalNumberOfBytes = 0;[/FONT]
[FONT=Courier New][color=teal]UInt32[/color] totalNumberOfFreeBytes = 0;[/FONT]
[FONT=Courier New]rootPathName = txtDriveLetter.Text + [color=maroon]":\\"[/color];[/FONT]
[FONT=Courier New][color=teal]Win32API[/color].GetDiskFreeSpaceEx(rootPathName,[color=blue]ref[/color] freeBytesToCaller,[color=blue]ref[/color] totalNumberOfBytes,[/FONT]
[FONT=Courier New][color=blue]ref[/color] totalNumberOfFreeBytes);[/FONT]
[FONT=Courier New]txtFunctionOutput.Text = [color=maroon]"Number of Free Bytes: "[/color] +[/FONT]
[FONT=Courier New]totalNumberOfFreeBytes.ToString();[/FONT]
[FONT=Courier New]}[/FONT][/align]