Jump to content
Sign in to follow this  
AmphetaMarinE

How to list available drive letters?

Recommended Posts

AmphetaMarinE

Hi,

I am absolutely stuck here...

How might I go about listing all available drive letters on a PC?

I want to put them into a combobox to enable choosing of an available (unused) drive letter for mapping a path to....

Completely stumped hey....

Thanks for any ideas,

Amph.

Share this post


Link to post
Share on other sites
AmphetaMarinE

DriveGetDrive()

Thanks Zedna, at least I know I'm on the right track...

I have been trying by using DriveGetDrive("all")

But that returns currently assigned drive letters...

I am stuck trying to return all unassigned driveletters...

I am quite new to all things programming, including autoit scripting...

Not saying I need someone to do the work for me, just a nudge in the right direction....

Share this post


Link to post
Share on other sites
Danny35d

Try this one:

#include <Array.au3>

$FreeDriveList = _GetFreeDriveLetters()
_ArrayDisplay($FreeDriveList)

Func _GetFreeDriveLetters()
    Dim $aArray[1]
    For $x = 67 To 90
        If DriveStatus(Chr($x) & ':\') = 'INVALID' Then
            ReDim $aArray[UBound($aArray) + 1]
            $aArray[UBound($aArray) - 1] = Chr($x) & ':'            
        EndIf
    Next
    $aArray[0] = UBound($aArray) - 1    
    Return($aArray)
EndFunc

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites
AmphetaMarinE

Try this one:

#include <Array.au3>

$FreeDriveList = _GetFreeDriveLetters()
_ArrayDisplay($FreeDriveList)

Func _GetFreeDriveLetters()
    Dim $aArray[1]
    For $x = 67 To 90
        If DriveStatus(Chr($x) & ':\') = 'INVALID' Then
            ReDim $aArray[UBound($aArray) + 1]
            $aArray[UBound($aArray) - 1] = Chr($x) & ':'            
        EndIf
    Next
    $aArray[0] = UBound($aArray) - 1    
    Return($aArray)
EndFunc
Ahhh now that works perfectly Danny35d :)

Thanks a million for that one!

Could I trouble you for one last question though?

What do the numbers represent in this line?

For $x = 67 To 90

I found I can change them and drives below C: are then listed, but I am unsure how you know which numbers to use, and what they actually represent...

Thanks again,

Amph.

Share this post


Link to post
Share on other sites
Danny35d

For $x = 67 To 90

I found I can change them and drives below C: are then listed, but I am unsure how you know which numbers to use, and what they actually represent...

Thanks again,

Amph.

Look at the if statement Im using Chr() function which return a character corresponding to an ASCII code. In the ASCII table 67 is equal to upper case C and 90 is equal to upper case Z. If you want to start in D and over change 67 to a 68.

Note fix some typo

Edited by Danny35d

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites
AmphetaMarinE

Look at the if statement Im using Chr() function which return a character corresponding to an ASCII code. In the ASCII table 67 is equal to upper case B and 90 is equal to upper case Z.

Ahhh thanks so much for the explanation.

Now I can see how it all works :)

Cheers,

Amph.

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  

×