0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

cscの作法 その570

Posted at

概要

cscの作法、調べてみた。
ドライブを表示するアプリ見つけたので、やってみた。

サンプルコード


using System;
using System.Linq;
using System.Management;
using System.Collections.Generic;
using System.Windows;
using System.IO;

public class USBUtil {
	public static bool EsUnidadExterna(string elPath) {
		var disco = Path.GetPathRoot(Path.GetFullPath(elPath));
		var usbD = GetUsbDriveLetters();
		return usbD.Contains(disco);
	}
	public static List<string> GetUsbDriveLetters() {
		var usbDrivesLetters = from drive in new ManagementObjectSearcher("select * from Win32_DiskDrive WHERE MediaType like '%External%' OR InterfaceType='USB'").Get().Cast<ManagementObject>()
							   from o in drive.GetRelated("Win32_DiskPartition").Cast<ManagementObject>()
							   from i in o.GetRelated("Win32_LogicalDisk").Cast<ManagementObject>()
							   select string.Format("{0}\\", i["Name"]);
		return usbDrivesLetters.ToList();
	}
}
class Program {
	static void Main(string[] args) {
		foreach (var dr in DriveInfo.GetDrives())
			Console.WriteLine("Unidad: {0}, tipo: {1}, label: {2}, fmt: {3}", dr.Name, dr.DriveType, dr.VolumeLabel, dr.DriveFormat);
		Console.WriteLine();
		var usb = USBUtil.GetUsbDriveLetters();
		foreach (var s in usb)
			Console.WriteLine("{0}", s);
		Console.WriteLine();
	}
}


実行結果

>usbu0
Unidad: C:\, tipo: Fixed, label: Windows, fmt: NTFS
Unidad: D:\, tipo: Removable, label: , fmt: FAT32

D:\

以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?