Jump to content

Help finding first unused drive letter


 Share

Recommended Posts

:P

Does someone know about a command or script that can find the first available drive letter?

I know about using the DriveMapAdd command, and using the "*" parameter to assign the first unused drive letter, but the Help file also states that "If there was an error using "*" then a blank string "" will be returned." I want to be able to determine what the error is if one is returned.

Any help would be much appreciated

:D

Edited by HockeyFan
Link to comment
Share on other sites

Example from DriveGetDrive in the helpfile.

$var = DriveGetDrive( "all" )
If NOT @error Then
    MsgBox(4096,"", "Found " & $var[0] & " drives")
    For $i = 1 to $var[0]
        MsgBox(4096,"Drive " & $i, $var[$i])
    Next
EndIf

That will show you used drives so you can work out the next available drive letter.

:P

Edit:

Added "letter".

Edited by MHz
Link to comment
Share on other sites

$drive = StringSplit("c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z",",",1)

For $i = 1 to $drive[0] step +1
    $var = DriveStatus( $drive[$i] & ":" )
    If $var = "INVALID" Then 
        MsgBox(1,"Free:","The first free letter: " & $drive[$i])
        Exit
    EndIf
Next

Neo

Edited by NeoFoX

[center][font="Arial"]--- The Neo and Only --- [/font][font="Arial"]--Projects---[/font]Image to Text converterText to ASCII converter[/center]

Link to comment
Share on other sites

Example from DriveGetDrive in the helpfile.

$var = DriveGetDrive( "all" )
If NOT @error Then
    MsgBox(4096,"", "Found " & $var[0] & " drives")
    For $i = 1 to $var[0]
        MsgBox(4096,"Drive " & $i, $var[$i])
    Next
EndIf

That will show you used drives so you can work out the next available drive letter.

:P

Edit:

Added "letter".

Yes, I saw that example...but I'm not wanting to display this during the execution of the script, nor am I wanting to select the drive letter. I was just hoping to find some code that found the first available drive letter and then used that drive letter to map a network connection.
Link to comment
Share on other sites

$drive = StringSplit("c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z",",",1)

For $i = 1 to $drive[0] step +1
    $var = DriveStatus( $drive[$i] & ":" )
    If $var = "INVALID" Then 
        MsgBox(1,"Free:","The first free letter: " & $drive[$i])
        Exit
    EndIf
Next

Neo

Thanks Neofox...this looks like it could work for me! :P
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...