Jump to content
Sign in to follow this  
meekaah

Get drive letter from drive label

Recommended Posts

meekaah

Hi, im looking for a way to find a drive letter from a drive label

I want to be able to find a specific drive letter that will allways have the same label "MYPHONE"

so i was thinking to do a loop through all usb removable devices with $drive=DriveGetDrive( "removable" )

and get the labels with DriveGetLabel($drive)

but cant find a way

please help

:)

Share this post


Link to post
Share on other sites
meekaah

something like

$var = DriveGetDrive( "removable" )

For $i = 1 to $var[0]
$name = DriveGetLabel($var[$i])
Next


Do
    Sleep(100)  
Until $name = "MYPONE"

MsgBox(64,"Info", "Found!")

But it doesnt work..

Share this post


Link to post
Share on other sites
weaponx

something like

$var = DriveGetDrive( "removable" )
  
  For $i = 1 to $var[0]
  $name = DriveGetLabel($var[$i])
  Next
  
  
  Do
      Sleep(100)    
  Until $name = "MYPONE"
  
  MsgBox(64,"Info", "Found!")

But it doesnt work..

Loops don't run in parallel. That second loop will do nothing until the first completes.

$var = DriveGetDrive( "removable" )

For $i = 1 to $var[0]
$name = DriveGetLabel($var[$i])
If $name = "MYPONE" Then
MsgBox(64,"Info", "Found!")
EndIf
Next
Edited by weaponx

Share this post


Link to post
Share on other sites
meekaah

AH thanks, i knew there was a problem of this kind

i had to modify your code a little bit but it works perfet

thanks

$var = DriveGetDrive( "removable" )
$usb = "MYPHONE"

For $i = 1 to $var[0]
$name = DriveGetLabel($var[$i])
If $name = $usb Then
MsgBox(64,"Info", "Found!")
EndIf
Next

Share this post


Link to post
Share on other sites
meekaah

Oh but now that i actually think of it, how would i know WHICH letter drive is associated to "MYPHONE" label, once it is found...? :)

EDIT ok nevermnd i dont take the time to think a little bit , my bad

$var = DriveGetDrive( "removable" )
$usb = "MYPHONE"

For $i = 1 to $var[0]
$name = DriveGetLabel($var[$i])
If $name = $usb Then
MsgBox(64,"Info", "MYPHONE found in "& $var[$i] & "\")
EndIf
Next
Edited by meekaah

Share this post


Link to post
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
Sign in to follow this  

×