2

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.

Thousand
  • 6,562
  • 3
  • 38
  • 46
Lee Denbigh
  • 80
  • 1
  • 5
  • http://stackoverflow.com/questions/3331043/get-list-of-connected-usb-devices have you checked this out ? – Thousand Sep 23 '12 at 16:11

1 Answers1

0

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
    {
        // ...
    }
}
Tudor
  • 61,523
  • 12
  • 102
  • 142
  • Hi, Thanks for the reply. I am trying to do this, but I can't figure out how to add the text file to the drive. How would I go about that? any ideas? – Lee Denbigh Sep 23 '12 at 19:38
  • @Lee Denbigh: Do you have the file on some other drive, or do you want to generate it from the program? – Tudor Sep 23 '12 at 20:59
  • I have the file on the removable drive, but I would like to create it if it is missing. – Lee Denbigh Sep 25 '12 at 12:04
  • Thanks mate. I must of been being dopey when I asked that, becasue it was totally straight forward. I just saved it to "drive". Thanks a lot for that! – Lee Denbigh Sep 25 '12 at 17:55
  • @Lee Denbigh: No problem. Please don't forget to mark the answer as accepted if it solved your problem. – Tudor Sep 25 '12 at 18:09