Jump to content

Get drive letter from drive label


Recommended Posts

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

:)

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
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...