I have looked everywhere, but have found nothing that is right for what I am after.

I am making a utility for my LED lights. I need to save a text file named hy.txt onto my SD card. Obviously, depending on what you have plugged in the drive letter can change every time. So I have renamed my SD card to STAR-LIGHT.

I have no idea how to search for the name, I have, however, only seen people looking for the drive letter.

I'm not sure if this makes much sense. Please feel free to ask me any questions.

有帮助吗?

解决方案

This "might" work (only tried with a USB drive and my HDD partitions):

string[] drives = Environment.GetLogicalDrives();
foreach (string drive in drives)
{
    try
    {
        DriveInfo di = new DriveInfo(drive);
        if (di.VolumeLabel == "STAR-LIGHT")
        {
            // code
        }
    }
    catch
    {
        // ...
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top