C# में किसी ड्राइव का फाइल सिस्टम फॉर्मेट (जैसे NTFS, FAT32, exFAT, ext4 आदि) जानने के लिए DriveInfo.DriveFormat प्रॉपर्टी का उपयोग किया जाता है।
उदाहरण
using System;
using System.IO;
public class Demo
{
public static void Main()
{
try
{
// C: ड्राइव के लिए DriveInfo ऑब्जेक्ट बनाएं
DriveInfo drive = new DriveInfo("C");
if (drive.IsReady)
{
Console.WriteLine($"ड्राइव: {drive.Name}");
Console.WriteLine($"फाइल सिस्टम: {drive.DriveFormat}");
Console.WriteLine($"ड्राइव प्रकार: {drive.DriveType}");
Console.WriteLine($"वॉल्यूम लेबल: {drive.VolumeLabel}");
}
else
{
Console.WriteLine("ड्राइव तैयार नहीं है या एक्सेस नहीं हो सकता।");
}
}
catch (Exception ex)
{
Console.WriteLine($"त्रुटि: {ex.Message}");
}
}
}
आउटपुट (Windows)
ड्राइव: C:\ फाइल सिस्टम: NTFS ड्राइव प्रकार: Fixed वॉल्यूम लेबल: Windows
आउटपुट (Linux)
ड्राइव: / फाइल सिस्टम: ext4 ड्राइव प्रकार: Fixed वॉल्यूम लेबल:
सामान्य फाइल सिस्टम फॉर्मेट
| ऑपरेटिंग सिस्टम | सामान्य फॉर्मेट |
|---|---|
| Windows | NTFS, FAT32, exFAT, ReFS |
| Linux | ext4, ext3, ext2, XFS, Btrfs, ZFS |
| macOS | APFS, HFS+ |
सभी ड्राइव्स के फॉर्मेट दिखाने का उदाहरण
using System;
using System.IO;
public class Demo
{
public static void Main()
{
DriveInfo[] drives = DriveInfo.GetDrives();
Console.WriteLine("ड्राइव\t\tफॉर्मेट\t\tप्रकार");
Console.WriteLine(new string('-', 40));
foreach (DriveInfo drive in drives)
{
if (drive.IsReady)
{
Console.WriteLine($"{drive.Name}\t{drive.DriveFormat}\t\t{drive.DriveType}");
}
else
{
Console.WriteLine($"{drive.Name}\t(तैयार नहीं)\t{drive.DriveType}");
}
}
}
}
महत्वपूर्ण बिंदु
DriveFormatप्रॉपर्टी केवल तभी काम करती है जब ड्राइव तैयार हो (IsReady == true)- अमान्य ड्राइव अक्षर (जैसे "Z:" जब वह मौजूद नहीं है) के लिए
DriveInfoऑब्जेक्ट बनाया जा सकता है, लेकिनIsReadyfalse होगा - नेटवर्क ड्राइव्स के लिए भी यह काम करता है
- CD/DVD ड्राइव्स के लिए मीडिया डाले जाने पर ही फॉर्मेट दिखेगा