Jump to content

get drive letter based on label


 Share

Recommended Posts

i have a flash drive with the volume label called "data"

but if i plug this into multiple computers, the drive letter will change, ect ect

and i want to populate the drive letter into my gui input

here is what i have so far,

$var1 = DriveGetLabel("data")
$var2 = DriveGetDrive("$var1")


$Input1 = GUICtrlCreateInput($var2, 16, 56, 281, 28)

am i close?

Link to comment
Share on other sites

DriveGetDrive requires a type, not a name. Also, if you're going to use a variable, you can't put it inside quotes like that.

DriveGetLabel needs a path to the drive.

You should probably use DriveGetDrive using Removable as the type, then loop through the array with DriveGetLabel using the contents of the array, to get the drive with the right name.

Something like this should work, untested though.

Local $aArray = DriveGetDrive("removable")
If @error Then
    ; An error occurred when retrieving the drives.
    MsgBox(4096, "DriveGetDrive", "It appears an error occurred.")
Else
    For $i = 1 To $aArray[0]
        If DriveGetLabel($aArray[$i]) = "data" Then
            MsgBox(4096, "DriveGetLabel", "Drive " & $aArray[$i] & " found with the label Data')
        EndIf
    Next
EndIf

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Just a little modify to BrewManNH code, this will skip the floppy drive from the loop. If you have a floppy drive installed on your pc, DriveGetLabel("floppydriver") can be very slow, for example in my system take ~ 3sec.

Local $aArray = DriveGetDrive("REMOVABLE")
If @error Then
    ; An error occurred when retrieving the drives.
    MsgBox(4096, "DriveGetDrive", "It appears an error occurred.")
Else
    For $i = 1 To $aArray[0]
        If $aArray[$i] = "a:" Then ContinueLoop ;Usually assigned to floppy driver, yep i still have a floppy drive in my pc :P
        If DriveGetLabel($aArray[$i]) = "data" Then
            MsgBox(4096, "DriveGetLabel", "Drive " & $aArray[$i] & " found with the label Data")
        EndIf
    Next
EndIf

Hi!

My UDF: NetInfo UDF Play with your network, check your download/upload speed and much more! YTAPI Easy to use YouTube API, now you can easy retrive all needed info from a video. NavInfo Check if a specific browser is installed and retrive other usefull information. YWeather Easy to use Yahoo Weather API, now you can easily retrive details about the weather in a specific region. No-IP UDF Easily update your no-ip hostname(s).

My Script: Wallpaper Changer Change you wallpaper dinamically, you can also download your wallpaper from your website and share it with all!   My Snippet: _ImageSaveToBMPConvert an image to bmp format. _SciteGOTO Open a file in SciTE at specific fileline. _FileToHex Show the hex code of a specified file

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...