名前、総容量、空き容量、フォーマットの種類など、USB デバイスの情報を保存できるソフトウェアを作成しようとしています。DriveInfo[] を使用しましたが、方法がわかりません。各個別のピースを異なる USB デバイス用に個別に保存するので、どの USB デバイスがどの情報に適用されるかがわかります。各 USB デバイスとその情報をテキスト ファイルに保存しようとしています。ここに私が持っているものがあります:
DriveInfo[] loadedDrives = DriveInfo.GetDrives();
foreach (DriveInfo ld in loadedDrives)
{
if (ld.DriveType == DriveType.Removable)
{
if (ld.IsReady == true)
{
deviceInfo.Add(ld.VolumeLabel + ": , " + ld.TotalSize + ": , " + ld.AvailableFreeSpace + ": , " + ld.DriveFormat);
}
}
}
foreach (String st in deviceInfo)
{
string[] deviceSel;
// DriveInfo dInfo;
deviceSel = st.Split(splitChar);
if (itemSelected.Contains(deviceSel[0]))
{
//Check That USB drive is the one thats selected
MessageBox.Show(deviceSel[0]);
break;
}
}
私がやったことよりも簡単な方法はありますか?問題を解決しようとすればするほど、コードが複雑になるからです。乾杯