Question

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.

Était-ce utile?

La solution

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
    {
        // ...
    }
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top