Jump to content

show available letter drives in combo


luis713
 Share

Recommended Posts

i'm trying to get all available letters that are not being used by a drive, I have this code but I think there shoulde be a better way without using a lot of lines

#include  'windowsconstants.au3'

#include  'guiconstantsex.au3'

#include  'comboconstants.au3'




; example 1

Local $msg

GUICreate("My GUI") ; will create a dialog box that when displayed is centered

$Unidad = GUICtrlCreateCombo("Seleccione la unidad", 20, 20, 200, 20, $CBS_DROPDOWNLIST)

GUISetState(@SW_SHOW) ; will display an empty dialog box

; Run the GUI until the dialog is closed

detectusb()

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

WEnd

GUIDelete()

Func detectusb()

If Not FileExists("C:") Then GUICtrlSetData($Unidad, "C:")

If Not FileExists("d:") Then GUICtrlSetData($Unidad, "d:")

If Not FileExists("e:") Then GUICtrlSetData($Unidad, "e:")

If Not FileExists("f:") Then GUICtrlSetData($Unidad, "f:")

If Not FileExists("g:") Then GUICtrlSetData($Unidad, "g:")

If Not FileExists("h:") Then GUICtrlSetData($Unidad, "h:")

If Not FileExists("i:") Then GUICtrlSetData($Unidad, "i:")

If Not FileExists("j:") Then GUICtrlSetData($Unidad, "j:")

If Not FileExists("k:") Then GUICtrlSetData($Unidad, "k:")

If Not FileExists("l:") Then GUICtrlSetData($Unidad, "l:")

If Not FileExists("m:") Then GUICtrlSetData($Unidad, "m:")

If Not FileExists("n:") Then GUICtrlSetData($Unidad, "n:")

If Not FileExists("o:") Then GUICtrlSetData($Unidad, "o:")

If Not FileExists("p:") Then GUICtrlSetData($Unidad, "p:")

If Not FileExists("q:") Then GUICtrlSetData($Unidad, "q:")

If Not FileExists("r:") Then GUICtrlSetData($Unidad, "r:")

If Not FileExists("s:") Then GUICtrlSetData($Unidad, "s:")

If Not FileExists("t:") Then GUICtrlSetData($Unidad, "t:")

If Not FileExists("u:") Then GUICtrlSetData($Unidad, "u:")

If Not FileExists("v:") Then GUICtrlSetData($Unidad, "v:")

If Not FileExists("w:") Then GUICtrlSetData($Unidad, "w:")

If Not FileExists("x:") Then GUICtrlSetData($Unidad, "x:")

If Not FileExists("y:") Then GUICtrlSetData($Unidad, "y:")

If Not FileExists("z:") Then GUICtrlSetData($Unidad, "z:")

EndFunc
<GUIConstantsEx.au3><GUIConstantsEx.au3>
Link to comment
Share on other sites

You could shorten it to this:

#include  'windowsconstants.au3'
#include  'guiconstantsex.au3'
#include  'comboconstants.au3'

Local $msg
GUICreate("My GUI") ; will create a dialog box that when displayed is centered
$Unidad = GUICtrlCreateCombo("Seleccione la unidad", 20, 20, 200, 20, $CBS_DROPDOWNLIST)
GUISetState(@SW_SHOW) ; will display an empty dialog box
; Run the GUI until the dialog is closed
detectusb()
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()
Func detectusb()
    For $i = 65 To 90
        If Not FileExists(Chr($i) & ":") Then GUICtrlSetData($Unidad, Chr($i) & ":")
    Next
EndFunc   ;==>detectusb

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

65 to 90 replaces the letters? it works great :guitar: only one question, if I want to use it to get all drives listed on my pc with label, how can i modify it? because i tryied to adding drivegetlabel but it doesn't work, is it possible? or when i use drivegetlabel i need specify the drive?

Edited by luis713
Link to comment
Share on other sites

yeah, also i want to list all available drives, but i want to list them with its label, free space, sorry for my mistake but i want to do this too because i have a similar script and i wish improve my code

Edited by luis713
Link to comment
Share on other sites

luis713,

Modifying the code that water gave you slightly. This should get you on your way. See the help file for other drive functions (under drive* and _winapi_drive*).

#include 'windowsconstants.au3'
#include 'guiconstantsex.au3'
#include 'comboconstants.au3'
Local $msg
GUICreate("My GUI") ; will create a dialog box that when displayed is centered
$Unidad = GUICtrlCreateCombo("Seleccione la unidad", 20, 20, 200, 20, $CBS_DROPDOWNLIST)
GUISetState(@SW_SHOW) ; will display an empty dialog box
; Run the GUI until the dialog is closed
detectusb()
While 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()
Func detectusb()
For $i = 65 To 90
     If drivestatus(chr($i) & ':') = 'INVALID' Then
GUICtrlSetData($Unidad, Chr($i) & ":" & ' drive is available')
Else
guictrlsetdata($Unidad, chr($i) & ':' & drivegetlabel(chr($i) & ':'))
endif
Next
EndFunc ;==>detectusb

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

DriveGetDrive("ALL") will return an array of mapped drives....also, DriveMapAdd ("*",...) will auto assign an available Drive.

edit: just throwing this out, because it may help get around needing the combo at all.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

luis713,

Changed the font and formatting slightly (PS fonts look goofy as hell in a combo box)

;~ local $aDrives = drivegetdrive('ALL'), $out_str
;~ for $i = 1 to $aDrives[0]
;~  $out_str &= stringupper($aDrives[$i]) & drivegetlabel($aDrives[$i] & '') & @crlf
;~  If @error  = 1 then consolewrite('! error')
;~ Next
;~ consolewrite($out_str & @lf)
#include  'windowsconstants.au3'
#include  'guiconstantsex.au3'
#include  'comboconstants.au3'
Local $msg
GUICreate("My GUI")
$Unidad = GUICtrlCreateCombo("Seleccione la unidad", 20, 20, 200, 20, $CBS_DROPDOWNLIST)
guictrlsetfont(-1,default,default,default,'courier new')
GUISetState(@SW_SHOW)
detectusb()
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()
Func detectusb()
    For $i = 65 To 90
        If drivestatus(chr($i) & ':') = 'INVALID' Then
   GUICtrlSetData($Unidad, Chr($i) & ":" & ' - drive is available')
  Else
   guictrlsetdata($Unidad, chr($i) & ': - ' & drivegetlabel(chr($i) & ':'))
  endif
    Next
EndFunc   ;==>detectusb

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

65 to 90 replaces the letters?

It doesn't replace the letters it just uses their ASCII value to process them in a loop.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

thanks to everybody, this code is all I need, it looks for removable drives and list them with its label and free space

#include 'windowsconstants.au3'

#include 'guiconstantsex.au3'

#include 'comboconstants.au3'

Local $msg

GUICreate("My GUI")

$Unidad = GUICtrlCreateCombo("Seleccione la unidad", 20, 20, 200, 20, $CBS_DROPDOWNLIST)

guictrlsetfont(-1,default,default,default,'courier new')

GUISetState(@SW_SHOW)

detectusb()

While 1

$msg = GUIGetMsg()

If $msg = $GUI_EVENT_CLOSE Then ExitLoop

WEnd

GUIDelete()

Func detectusb()

For $i = 65 To 90

If drivestatus(chr($i) & ':') = 'READY' Then

If DriveGetType(chr($i) & ":") = 'REMOVABLE' Then guictrlsetdata($Unidad, chr($i) & ': - ' & drivegetlabel(chr($i) & ':') & " " & int(DriveSpaceFree(chr($i) & ":")) & "Mb")

EndIf

Next

EndFunc ;==>detectusb
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...