Linux 在 C#/Mono 中处理外部媒体
Handling external media in C#/Mono on Linux
我想要做的是检测 Raspberry-Pi USB 插槽中是否存在外部记忆棒,然后尝试向其读取或写入文件。读取或写入很简单(StreamReader 等),但实际路径不明确。
在 Windows 上是 D:、E: 等。我看了很多,但似乎很难找到有关在代码中处理外部设备的信息。
您可以使用方法 System.IO.DriveInfo.GetDrives
其中 return DriveInfo[]
DriveInfo 还有一个枚举类型的 DriveType 属性,可能会有用:
CDRom 5 The drive is an optical disc device, such as a CD or DVD-ROM.
Fixed 3 The drive is a fixed disk.
Network 4 The drive is a network drive.
NoRootDirectory 1 The drive does not have a root directory.
Ram 6 The drive is a RAM disk.
Removable 2 The drive is a removable storage device, such as a USB
flash drive.
Unknown 0 The type of drive is unknown.
我想要做的是检测 Raspberry-Pi USB 插槽中是否存在外部记忆棒,然后尝试向其读取或写入文件。读取或写入很简单(StreamReader 等),但实际路径不明确。
在 Windows 上是 D:、E: 等。我看了很多,但似乎很难找到有关在代码中处理外部设备的信息。
您可以使用方法 System.IO.DriveInfo.GetDrives
其中 return DriveInfo[]
DriveInfo 还有一个枚举类型的 DriveType 属性,可能会有用:
CDRom 5 The drive is an optical disc device, such as a CD or DVD-ROM.
Fixed 3 The drive is a fixed disk.
Network 4 The drive is a network drive.
NoRootDirectory 1 The drive does not have a root directory.
Ram 6 The drive is a RAM disk.
Removable 2 The drive is a removable storage device, such as a USB flash drive.
Unknown 0 The type of drive is unknown.