如何以编程格式化SD卡支持FAT16? [英] How to programatically format an SD card with FAT16?

查看:304
本文介绍了如何以编程格式化SD卡支持FAT16?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想初始化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("\r\n");

    	p.WaitForExit();

    }
}

这篇关于如何以编程格式化SD卡支持FAT16?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆