Jump to content

How to list available drive letters?


Recommended Posts

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

Link to comment
Share on other sites

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

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.

Link to comment
Share on other sites

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