sách gpt4 ăn đã đi

C# 检查是否存在 USB 驱动器

In lại Tác giả: Walker 123 更新时间:2023-11-30 14:39:27 27 4
mua khóa gpt4 giày nike

我正在编写一个提取 xml 的文件以获取文件名,并且需要将这些文件复制到 USB 驱动器。前两个步骤我能够做到这一点。但问题是:

  1. 如何检测是否有 U 盘
  2. 然后检测它是哪个驱动器。

Cảm ơn!

câu trả lời hay nhất

这段代码的方向相反,但它处理的是“我如何找到 USB 驱动器”的问题:

 using System.IO;

//。 . .

        foreach (DriveInfo removableDrive in DriveInfo.GetDrives().Where(
d => d.DriveType == DriveType.Removable && d.IsReady))
{
DirectoryInfo rootDirectory = removableDrive.RootDirectory;
string monitoredDirectory = Path.Combine(rootDirectory.FullName, DIRECTORY_TO_MONITOR);
string localDestDirectory = Path.Combine(destDirectory, removableDrive.VolumeLabel);
if (!Directory.Exists(localDestDirectory))
Directory.CreateDirectory(localDestDirectory);
if (Directory.Exists(monitoredDirectory))
{
foreach (string file in Directory.GetFiles(monitoredDirectory))
{
File.Copy(file, Path.Combine(localDestDirectory, Path.GetFileName(file)), true);
}
}
}

关于C# 检查是否存在 USB 驱动器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6391167/

27 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress