Home > Back-end >  In VB, can I access an external hard drive using the drive name rather than the letter?
In VB, can I access an external hard drive using the drive name rather than the letter?

Time:11-26

This question seems similar to some I found here, but I didn't understand the replies they got. I have a VB process that will sometimes be writing to an external hard drive. This drive may be plugged in, unplugged, plugged in again etc. I have a literal for the drive, but as I understand it there's a chance it could have a different drive letter assigned each time it's plugged in. My question is simply this: Is there a way I can use the drive name or label (I'm not sure what the correct term in) to find the drive letter assigned, or, better yet, write to the drive using only the name/label? For the time being, we'll assume the drive is plugged in when the process runs so we don't have to check for that. I don't have a lot of experience in VB so please keep replies simple.

CodePudding user response:

I found that by scrolling through the drive info for all active drives, I can see if one has the correct VolumeLabel. If it does, then I just take the name for that drive. This also provides an easy way to check whether or not the drive is plugged in - if it isn't then the variable that I created to store the name and initialized to null will still be empty.

  • Related