Sign in to follow this  
Followers 0
wi1d

Map to drives

4 posts in this topic

#1 ·  Posted (edited)

I'm wanting to populate a combo box with drives that are available to map to. So I have to somehow minus all drives that are already in use.

I've racked my brain and search the site and haven't come up with anything besides possible creating an array to list A: - Z: and then using DriveGetDrive() and to compare the two to find what drives are available. However I'm sure there has to be a better way and was wondering if anyone has a suggestion. Thanks.

Edited by wi1d

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Something like:

Dim $AllDrives
For $x = 1 to 26
    $AllDrives = $AllDrives & "|" & chr(96+$x) & ":"
Next
$var = DriveGetDrive( "all" )
If NOT @error Then
    For $i = 1 to $var[0]
        $AllDrives = StringReplace($AllDrives,"|" & $var[$i],"")
    Next
EndIf

and use $AllDrives in your Combobox

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

@JdeB: That's hard to follow....

I'm pretty sure that DriveStatus will do what you want. The message box is included to help debug....

$debug = "Drive" & @TAB & "Status" & @TAB & @TAB & "GetType" & @TAB & "MapGet" & @LF
$debug = $debug & "------" & @TAB & "-------" & @TAB & @TAB &  "-------" & @TAB & "-------"

$list = ""
For $i = Asc("B") to Asc("Z")
    $drive = Chr($i) & ":"
    If DriveStatus($drive) = "INVALID" Then $list = $list & $drive & "|"
    $debug = $debug & @LF & $drive & @TAB & DriveStatus($drive) & @TAB & @TAB & DriveGetType($drive) &  @TAB & DriveMapGet($drive)
Next

#include <GuiConstants.au3>
GuiCreate("Example", -1, -1, 100, 100);change default posotion
    $combo = GuiCtrlCreateCombo("",50, 50, 100, 200, $CBS_DROPDOWNLIST)
    $defaultSelection = StringLeft($list,StringInStr($list,":"));the first drive letter
    $infoButton = GuiCtrlCreateButton("Debug", 200, 100, 100, 50)
    GuiCtrlSetData($combo, $list,  $defaultSelection)
GuiSetState(@SW_SHOW)

While 1
    $msg = GuiGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
    If $msg = $infoButton Then MsgBox(4096,"For Debugging", $debug)
WEnd

Edit: Improved example.

Edited by CyberSlug

Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!

Share this post


Link to post
Share on other sites

Thanks for both examples. I really liked your use of Asc, Chr, w/ the loop. Great stuff, I wouldn't have thought of that. Thanks again.

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  
Followers 0