LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I address a Hard drive by its volume label, rather than its letter?

Hi All,

 

I have a question about file paths... I'm building an instrument and have a spare USB port internally. I want to use that to attach a simple flash drive to give the system on-board storage. The system itself is run by a separate PC to which it connects via a USB interface (there's a USB hub internal to the system, hence the spare USB port).

 

I've been able to format the USB flash drive and give it a label which shows up when the device is plugged into any computer. However, the drive letter associated with the device will vary from PC to PC since each PC may have a different number of drives already installed when I plug my system in. Is there a way to use my label to either address the flash drive directly, or at least to determine its drive letter within labview?

 

Thanks for your help

 

Paul Morris

0 Kudos
Message 1 of 9
(4,500 Views)
Microsoft may not want to admit it, but Windows is still DOS at its core when it comes down to disks. You can use the Windows API to get the volume label of a disk using the GetVolumeInformation function. Or, you could use .NET by using the static method DriveInfo.GetDrives(). Or, you could use the batch file shown here.
Message 2 of 9
(4,491 Views)

Thanks for the reply.

 

I don't suppose you could give me a little more detail on how to actually make this work within labview? Its a tad advanced for me! A simple example where I can enter a volume label and get the resulting drive letter would be most appreciated...

 

Thanks again!

 

Paul

0 Kudos
Message 3 of 9
(4,487 Views)

Attached are examples to do it using the batch file (note that I added the line echo %DRV% to the batch file) and .NET.

 

 

 

Download All
Message 4 of 9
(4,462 Views)

Sorry to be a continued pain... I don't suppose you could save those back to labview 8.0 could you?

 

thanks again for your help!

 

Paul

0 Kudos
Message 5 of 9
(4,431 Views)

Here they are in LV8.0

 

 

Message 6 of 9
(4,412 Views)

Thanks very much for the help and VIs. Apart from obviously needing to have the .bat file in the right place to use that method, is there any reason why I should chose one method over the other?

 

Is one method inherently better than the other?

 

Thanks again for your help

 

Paul

 

0 Kudos
Message 7 of 9
(4,403 Views)
The batch file method doesn't require that you have .NET. It has the drawback of displaying a command window momentarily. This may or may not be jarring. It also requires that you distribute the batch file with the app. I don't know if there are any permissions issues under Vista. The .NET solution is clean in the sense that it's self-contained. But, it requires you to have .NET. The Windows API method, which I didn't show, would be similar to the .NET solution.
0 Kudos
Message 8 of 9
(4,394 Views)

Thanks again for the help. I'll stick with the .bat file for distributable code - its not a problem to include the .bat file with the code, I suspect one could even use labview to create the .bat file if it's not found on the system?

 

Although I may use the .net version for in-house only stuff, since I know we have .net installed on the machines here.

 

Thanks again.

 

Kind regards

 

Paul Morris

0 Kudos
Message 9 of 9
(4,389 Views)