如何以编程格式化SD卡支持FAT16?SD

由网友(眼眸总是印着温柔)分享简介:我想初始化SD卡支持FAT16文件系统。假设我有我的SD读卡器驱动器G :,我怎么可以很容易地格式化为FAT16?I'd like to initialize an SD card with FAT16 file system. Assuming that I have my SD reader on drive...

我想初始化SD卡支持FAT16文件系统。 假设我有我的SD读卡器驱动器G :,我怎么可以很容易地格式化为FAT16?

I'd like to initialize an SD card with FAT16 file system. Assuming that I have my SD reader on drive G:, how I can easily format it to FAT16 ?

更新: 为了澄清,我想用的方式C#中,我可以检测到错误,并且将工作在Windows XP及以上做到这一点的.NET平台。

UPDATE: To clarify, I'd like to do that on .net platform using C# in a way that I can detect errors and that would work on Windows XP and above.

推荐答案

我尝试了上面的答案,可惜它不是简单的,因为它似乎...

I tried the answers above, unfortunately it was not simple as it seems...

第一个答案,使用管理对象看起来像这样只可惜不支持Windows XP中的格式方法的正确途径。

The first answer, using the management object looks like the correct way of doing so but unfortunately the "Format" method is not supported in windows xp.

第二和第三答案工作,但需要用户确认操作。

The second and the third answers are working but require the user to confirm the operation.

为了做到这一点,而无需用户进行任何干预我使用重定向过程的输入和输出流的第二个选项。当我只重定向输入流的过程中失败了。

In order to do that without any intervention from the user I used the second option with redirecting the input and output streams of the process. When I redirecting only the input stream the process failed.

下面是一个例子:

DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives)
{
    if (d.IsReady && (d.DriveType == DriveType.Removable))
    {
    	ProcessStartInfo startInfo = new ProcessStartInfo();
    	startInfo.FileName = "format";
    	startInfo.Arguments = "/fs:FAT /v:MyVolume /q " + d.Name.Remove(2);
    	startInfo.UseShellExecute = false;
    	startInfo.CreateNoWindow = true;
    	startInfo.RedirectStandardOutput = true;
    	startInfo.RedirectStandardInput = true;

    	Process p = Process.Start(startInfo);

    	StreamWriter processInputStream = p.StandardInput;
    	processInputStream.Write("rn");

    	p.WaitForExit();

    }
}
阅读全文

相关推荐

最新文章