Jump to content

Map to drives


wi1d
 Share

Recommended Posts

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

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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