2009-01-05 14 views

उत्तर

67

अधिक जानकारी के लिए, आप DriveInfo कक्षा का उपयोग कर सकते हैं।

using System; 
using System.IO; 

class Info { 
    public static void Main() { 
     DriveInfo[] drives = DriveInfo.GetDrives(); 
     foreach (DriveInfo drive in drives) { 
      //There are more attributes you can use. 
      //Check the MSDN link for a complete example. 
      Console.WriteLine(drive.Name); 
      if (drive.IsReady) Console.WriteLine(drive.TotalSize); 
     } 
    } 
} 
+1

अच्छा काम, धन्यवाद! – leo

+1

स्थानीय मशीन के अलावा मशीन पर ड्राइव जानकारी के बारे में क्या? – flipdoubt

+1

नेटवर्क के लिए यह काम करता है इस ड्राइव को ड्राइव करता है, ड्राइव प्रकार को "नेटवर्क" के रूप में रिपोर्ट करता है। दूरस्थ पूछताछ के लिए, मुझे लगता है कि आपको एक अलग सवाल पूछना चाहिए। –

2

चेक DriveInfo क्लास और देखें कि क्या यह सब जानकारी है कि आप की जरूरत होती है।

5

क्या घुड़सवार संस्करणों, जहां कोई ड्राइव अक्षर है के बारे में?

foreach(ManagementObject volume in 
      new ManagementObjectSearcher("Select * from Win32_Volume").Get()) 
{ 
    if(volume["FreeSpace"] != null) 
    { 
    Console.WriteLine("{0} = {1} out of {2}", 
        volume["Name"], 
        ulong.Parse(volume["FreeSpace"].ToString()).ToString("#,##0"), 
        ulong.Parse(volume["Capacity"].ToString()).ToString("#,##0")); 
    } 
} 
+1

बस इसे स्वयं पाया: '' foreach (प्रबंधन में ऑब्जेक्ट ऑब्जेक्ट ऑब्जेक्ट ऑब्जेक्ट सर्चर्स ("Win32_Volume से * चुनें *)।()) {If (वॉल्यूम [" फ्रीस्पेस "]! = Null) {Console.WriteLine (" {0 } = {1} {2} ", वॉल्यूम [" नाम "], ulong.Parse (वॉल्यूम [" फ्रीस्पेस "]। ToString())। ToString (" #, ## 0 "), ulong.Parse (वॉल्यूम ["क्षमता"]। ToString())। ToString ("#, ## 0")); }}} – Foozinator

+1

कृपया अपना उत्तर संपादित करें और कोड खंड को दोबारा पोस्ट करें। –

3

आप अपने स्थानीय मशीन पर एकल/विशिष्ट ड्राइव के लिए जानकारी प्राप्त करना चाहते हैं। आप इसे DriveInfo वर्ग का उपयोग करके पालन कर सकते हैं:

//C Drive Path, this is useful when you are about to find a Drive root from a Location Path. 
string path = "C:\\Windows"; 

//Find its root directory i.e "C:\\" 
string rootDir = Directory.GetDirectoryRoot(path); 

//Get all information of Drive i.e C 
DriveInfo driveInfo = new DriveInfo(rootDir); //you can pass Drive path here e.g DriveInfo("C:\\") 

long availableFreeSpace = driveInfo.AvailableFreeSpace; 
string driveFormat = driveInfo.DriveFormat; 
string name = driveInfo.Name; 
long totalSize = driveInfo.TotalSize; 
संबंधित मुद्दे