我有一个只能用可移动驱动器填充的ListBox。用户选择要格式化的驱动器,然后程序应格式化这些驱动器。但是,我收到无法找到指定文件的消息。这是我的代码。在Visual Basic中格式化驱动器?
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For Each Drive In My.Computer.FileSystem.Drives
'Gets drive letter and type
Dim DriveInfo As String = Drive.Name & " (" & Drive.DriveType.ToString & ")"
'Checks to see if drive is a removable drive
Dim removable = "Removable"
Dim isFlashDrive As Boolean = DriveInfo.Contains(removable)
'Adds only removable drives to the list
If isFlashDrive Then
ListBox1.Items.Add(DriveInfo)
End If
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs)
'Variables initialized
Dim i, j As Integer
Dim s, DrvsToFormat As String
'Stores all selected drives in an array named "drives" and creates string with drive letter
Dim drives(ListBox1.SelectedItems.Count) As String
For i = 0 To ListBox1.SelectedItems.Count - 1
s = ListBox1.SelectedItems(i).ToString.Substring(0, 2)
drives(i) = s
DrvsToFormat = DrvsToFormat & " " & ListBox1.SelectedItems(i).ToString.First()
Next
Dim response = MessageBox.Show("Are you sure you want to format drive(s) " & DrvsToFormat & "? All data will be lost.", "WARNING!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
If response = MsgBoxResult.Yes Then
For j = 0 To drives.Length() - 1
Console.WriteLine(drives(j))
Process.Start("format " & drives(j))
Next
MessageBox.Show("Format Complete!")
End If
End Sub
End Class
的就是你得到确切的错误消息,到底是哪行导致的呢? (我在'Process.Start'上投注,我也打赌快速浏览一下调试器中的驱动器(j)'会清楚地告诉你是什么导致了这个问题。) –
[你搜索了吗?](http://stackoverflow.com/questions/2271246/how-to-format-drive-in-fat-16-format-using-vb-net-without-user-interaction) – crashmstr