强制格式化USB驱动器 [英] forcefully format an usb drive

查看:67
本文介绍了强制格式化USB驱动器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何强制格式化USB驱动器?

How can I forcefully format an usb drive?

推荐答案

公共布尔Format_USB(string l_usbpath)
{
bool l_usbflag = false;

如果(l_usbpath.Length> 0)
{
//一旦格式化完成.
StreamWriter l_sw;
字符串l_fstype ="ntfs";
字符串l_vol_label =尼丁";

l_sw = File.CreateText(@"usb.bat");
l_sw.WriteLine("format" + l_usbpath +"/fs:" + l_fstype +"/v:" + l_vol_label +"/Q");
//l_sw.WriteLine(l_vol_label);
l_sw.Close();

System.Diagnostics.Process l_proc =新的System.Diagnostics.Process();
l_proc.StartInfo.FileName = @"usb.bat";
l_proc.StartInfo.UseShellExecute = false;
l_proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
l_proc.Start();
l_proc.WaitForExit();
File.Delete(@"usb.bat");

字符串[] l_files = Directory.GetFiles(l_usbpath);
string [] l_dir = Directory.GetDirectories(l_usbpath);
if(((l_files.Length == 0)&&(l_dir.Length == 0))
{
l_usbflag = true;
}
其他
{
l_usbflag = false;
}
}
return l_usbflag;
}


试试这个.
public bool Format_USB(string l_usbpath)
{
bool l_usbflag = false;

if (l_usbpath.Length > 0)
{
// once the format is done.
StreamWriter l_sw;
string l_fstype = "ntfs";
string l_vol_label = "Nitin";

l_sw = File.CreateText(@"usb.bat");
l_sw.WriteLine("format " + l_usbpath + " /fs:" + l_fstype + " /v:" + l_vol_label + " /Q");
//l_sw.WriteLine(l_vol_label);
l_sw.Close();

System.Diagnostics.Process l_proc = new System.Diagnostics.Process();
l_proc.StartInfo.FileName = @"usb.bat";
l_proc.StartInfo.UseShellExecute = false;
l_proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
l_proc.Start();
l_proc.WaitForExit();
File.Delete(@"usb.bat");

string[] l_files = Directory.GetFiles(l_usbpath);
string[] l_dir = Directory.GetDirectories(l_usbpath);
if ((l_files.Length == 0) && (l_dir.Length == 0))
{
l_usbflag = true;
}
else
{
l_usbflag = false;
}
}
return l_usbflag;
}


Try this.


这篇关于强制格式化USB驱动器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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