我想用FAT16文件系统初始化SD卡。假设我在驱动器G:上有我的SD阅读器,我如何能够轻松地将它格式化为FAT16?
更新:为了澄清,我想在平台上使用C#来检测错误,这可以在Windows和更高版本上使用。
发布于 2009-09-29 12:07:13
我试过上面的答案,不幸的是,它并不像看起来那么简单.
第一个答案是,使用管理对象似乎是正确的方法,但不幸的是,windows xp中不支持"Format“方法。
第二和第三答案正在工作,但需要用户确认操作。
为了做到这一点,而不需要用户的任何干预,我使用了第二个选项,即重定向流程的输入和输出流。当我只重定向输入流时,进程失败。
以下是一个例子:
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();
}
}发布于 2009-08-05 11:31:54
你可以用调用SHFormatDrive。
[DllImport("shell32.dll")]
static extern uint SHFormatDrive(IntPtr hwnd, uint drive, uint fmtID, uint options);
public enum SHFormatFlags : uint {
SHFMT_ID_DEFAULT = 0xFFFF,
SHFMT_OPT_FULL = 0x1,
SHFMT_OPT_SYSONLY = 0x2,
SHFMT_ERROR = 0xFFFFFFFF,
SHFMT_CANCEL = 0xFFFFFFFE,
SHFMT_NOFORMAT = 0xFFFFFFD,
}
//(Drive letter : A is 0, Z is 25)
uint result = SHFormatDrive( this.Handle,
6, // formatting C:
(uint)SHFormatFlags.SHFMT_ID_DEFAULT,
0 ); // full format of g:
if ( result == SHFormatFlags.SHFMT_ERROR )
MessageBox.Show( "Unable to format the drive" );发布于 2009-08-05 10:46:53
无法在DriveInfo等人中找到函数,但您可以始终使用(创建)包含Format G: /FS:FAT的批处理文件并使用System.Diagnostics.Process启动它
https://stackoverflow.com/questions/1232398
复制相似问题