Jump to content
Sign in to follow this  
johnmcloud

[SOLVED] DriveGetDrive + Comparison

Recommended Posts

johnmcloud

Hi Guys,

For work i need to know how which drive letter are avaiable and take the first.

For now i have make this script:

Local $aArray = DriveGetDrive("ALL")
Local $avArray[24]

$avArray[0] = "A:\"
$avArray[1] = "B:\"
$avArray[2] = "C:\"
$avArray[3] = "D:\"
$avArray[4] = "E:\"
$avArray[5] = "F:\"
$avArray[6] = "G:\"
$avArray[7] = "H:\"
$avArray[8] = "I:\"
$avArray[9] = "J:\"
$avArray[10] = "K:\"
$avArray[11] = "L:\"
$avArray[12] = "M:\"
$avArray[13] = "N:\"
$avArray[14] = "O:\"
$avArray[15] = "P:\"
$avArray[16] = "Q:\"
$avArray[17] = "R:\"
$avArray[18] = "S:\"
$avArray[19] = "T:\"
$avArray[20] = "U:\"
$avArray[21] = "V:\"
$avArray[22] = "X:\"
$avArray[23] = "Y:\"
$avArray[24] = "Z:\"

If @error Then
; An error occurred when retrieving the drives.
MsgBox(4096, "DriveGetDrive", "It appears an error occurred.")
Else
For $i = 1 To $aArray[0]
     ; Show all the drives found and convert the drive letter to uppercase.
     ConsoleWrite(StringUpper($aArray[$i]) & "\" & @CRLF)
Next
EndIf

Hope is a good approach.

The result of DriveGetDrive is:

C:\
D:\
W:\
X:\
Y:\
Z:\

So i want to compare mine letter with all avaible ( so the two array ), subtract from the complete list C-D-W-X-Y-Z and give me a new list, then take the fist drive avaiable ( in my case is E:\ = [1] )

Some suggestion?

Thanks ;)

Edited by johnmcloud

Share this post


Link to post
Share on other sites
water

If you need the first drive available for function DriveMapAdd you couldy just pass "*" to get the same result.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
johnmcloud

Water you are always here when i need help ;)

I have try:

ConsoleWrite(DriveMapAdd("*"))

But give me error, the second parameter is:

Remote Share --> The remote share to connect to in the form servershare.

What i need to write?

Thanks

Edited by johnmcloud

Share this post


Link to post
Share on other sites
water

The second parameter has to be the share you want to connect to. "" + Servername + "" + sharename. Sharename is something like "C$" for a complete drive on another computer or "name$" for a directory.

Where do you want to connect to?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
johnmcloud

I don't need to connect the drive, i need only to know the first drive letter avaiable

Share this post


Link to post
Share on other sites
water

But why do you want to know the first free drive letter? What do you want to do with this information?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
johnmcloud

It's a complex question to explain for me in my not native language, any way to compare the two result?

EDIT: Maybe like this:

#include <Array.au3>
Global $aArrayA[10] = ["A", "B", "C"]
Global $aArrayB[10] = ["A"]

For $a = UBound($aArrayA) - 1 To 0 Step -1
    For $b = 0 To UBound($aArrayB) - 1
        If $aArrayA[$a] = $aArrayB[$b] Then
            _ArrayDelete($aArrayA, $a)
            ExitLoop
        EndIf
    Next
Next
_ArrayDisplay($aArrayA, "Result")

I don't like ArrayDelete

Edited by johnmcloud

Share this post


Link to post
Share on other sites
water

This will return the next free drive letter:

For $i = Asc("A") To Asc("Z")
    $sDrive = DriveGetType(Chr($i) & ":")
    If @error Then ExitLoop
Next
MsgBox(0, "", Chr($i) & " is the next free drive letter")

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
johnmcloud

Cool thanks, more faster and shorter then mine solution

Share this post


Link to post
Share on other sites
water
:D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
guinness

What's wrong with _GetUnusedDrives()?


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
water

Nothing wrong with that.

But as the OP only needed the first free drive letter my code is a bit shorter and easier to understand ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
guinness

OK.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
Tlem

Hi, may be this one is more complete : http://www.autoitscript.fr/forum/viewtopic.php?t=10424#p72016


Best Regards.Thierry

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  

  • Similar Content

    • kristo
      By kristo
      The DriveGetDrive command returned all drives (option "ALL") for years now and my program could always rely on that function. Suddenly a drive letter that was created with the subst command does not appear in the list of drives anymore. And it clearly did, because I used to react to a certain subst command by reacting to new or revoked (subst /D) drive letters.
      Why is that? I think this a bug because there's no way left to list ALL drive letters anymore.
      And why should I use an API command for that when this was already built in for years?

       
    • MyEarth
      By MyEarth
      Hi, maybe is a silly question but i don't have understood how to make a list of internal HDD and external HDD-Pen Drive using DriveGetDrive
      FIXED = Internal HDDs, right?
      REMOVABLE = External HDDs - PenDrive, right?
      How to get both in the same list? Thanks
    • hackersarchangel
      By hackersarchangel
      I have a project I'm working on, as part of a maintenance disk. I want to make a GUI for automating chkdsk startup, as in I run the GUI, then I select what drives I'm wanting to chkdsk. I want to run this from a PE based enviroment, I believe the disk I've chosen is a BartPE based disk, if that matters.

      Here's where my issue comes into play. When I start the program I have it set to specify a log save location with a Save As box. That part works great, so I have it make the GUI. Here's the issue: When I'm making the GUI, I want it to grab the drive letters and use that as part of either Checkboxes OR multiple dropdown menus. That part I'm flexible on, I just want it to work, and the dropdown menus was just another way of thinking about it.

      So I figured out how to grab drive letters into an array and do an If-Then for less than 4 drives (test machine has 3 drives, trying to get it work before worrying about whether or not it's less than 2 or 3):



      Global $Drives[5] = ["1","2","3","4","5"] $Drives = DriveGetDrive("Fixed") If $Drives[0] < 4 Then $Drives[4] = "None" EndIf

      For some reason, when I run that code, it flips it's lid about being outside my subscript range. I added the ReDim command to resize it back to 5, but that still doesn't work. Now if I set it when I initialize it, it's fine, and I can edit it all I want to manually, just not with DriveGetDrive.

      Current modified code:


      Global $Drives[5] = ["1","2","3","4","5"] $Drives = DriveGetDrive("Fixed") If $Drives[0] < 4 Then ReDim $Drives[5] $Drives[4] = "None" EndIf
      What I would like to do is resize the Array to fix the amount of drives I have, i.e. if I have 2 drives, make it 3 slots big, [0] for the count it generates, [1] for drive 1, [2] for drive 2, etc. and if it doesn't get a reply from slots 3 and 4, disable those checkboxes/remove the entry from the dropdown list. But that is further complicating the issue as it is, just want the basic premise to work.

      If anyone has any ideas for this little issue, I'm welcoming the ideas.
    • GHOSTSKIKDA
      By GHOSTSKIKDA
      Hey guys,

      I'm trying to use the delete files same time in Removable or change attrib to show.

      ex: delete : Autorun.inf ===> Attrib = SH in Removable

      this is try me :


      #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.6.1 Author: GHOST SKIKDA Script Function: Hide Files System in Removable. #ce ---------------------------------------------------------------------------- #include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> #include <GuiStatusBar.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 554, 454, 192, 114) GUISetBkColor(0x000000) $ListView1 = GUICtrlCreateListView("Name|Status", 16, 168, 522, 270, '', BitOR($WS_EX_CLIENTEDGE,$LVS_EX_GRIDLINES)) _GUICtrlListView_SetExtendedListViewStyle(-1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES)) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 400) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x00FF00) GUICtrlSetBkColor(-1, 0x800000) $ListView1context = GUICtrlCreateContextMenu($ListView1) $MenuItem1 = GUICtrlCreateMenuItem("Show", $ListView1context) $MenuItem2 = GUICtrlCreateMenuItem("Hide", $ListView1context) $MenuItem3 = GUICtrlCreateMenuItem("Delete", $ListView1context) $Button1 = GUICtrlCreateButton("Scan", 462, 134, 75, 25, $WS_GROUP) $Combo1 = GUICtrlCreateCombo("", 50, 136, 409, 25) $Label1 = GUICtrlCreateLabel("Path : ", 16, 139, 35, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0xFF0000) $StatusBar1 = _GUICtrlStatusBar_Create($Form1) Dim $StatusBar1_PartsWidth[1] = [-1] _GUICtrlStatusBar_SetParts($StatusBar1, $StatusBar1_PartsWidth) _drivercombo() GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _GUICtrlListView_DeleteAllItems($ListView1) Sleep(200) ;Search("f:\") _driver() Case $ListView1 EndSwitch WEnd ;~ Func _Search() ;~ $search = FileFindFirstFile("C:\*.*") ;~ If $search = -1 Then ;~ MsgBox(0, "Error", "No files/directories matched the search pattern") ;~ Exit ;~ EndIf ;~ $com=0 ;~ While 1 ;~ $file = FileFindNextFile($search) ;~ If @error Then ExitLoop ;~ $var = FileGetAttrib("C:\"&$file) ;~ If ($var = "RASH") or ($var = "SH") Then ;~ _GUICtrlListView_AddItem($ListView1, $file, $com) ;~ _GUICtrlListView_AddSubItem($ListView1, $com,$var, 1) ;~ ;_GUICtrlListView_SetItemChecked($ListView1, $com) ;~ $com=$com+1 ;~ EndIf ;~ WEnd ;~ FileClose($search) ;~ _GUICtrlStatusBar_SetText($StatusBar1, @TAB & "Resultat = " & _GUICtrlListView_GetItemCount($ListView1), 0) ;~ EndFunc Func Search($current) Local $search = FileFindFirstFile($current & "\*.*") $com=0 While 1 Dim $file = FileFindNextFile($search) If @error Or StringLen($file) < 1 Then ExitLoop $var = FileGetAttrib($current &"\"&$file) If ($var = "RASH") or ($var = "SH") or ($var = "RAH") or ($var = "ASH") Then;StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") and _GUICtrlListView_AddItem($ListView1, $file, $com) _GUICtrlListView_AddSubItem($ListView1, $com,$var, 1) ;_GUICtrlListView_SetItemChecked($ListView1, $com) $com=$com+1 Search($current & "\" & $file) EndIf Sleep (1) _GUICtrlStatusBar_SetText($StatusBar1, @TAB & "Resultat = " & _GUICtrlListView_GetItemCount($ListView1), 0) WEnd EndFunc Func _driver() $drv = DriveGetDrive( "Removable") If NOT @error Then For $i = 2 to $drv[0] GUICtrlSetData($Combo1,$drv[$i]) Search($drv[$i]) Next EndIf EndFunc Func _drivercombo() $drv = DriveGetDrive( "Removable") If NOT @error Then For $i = 2 to $drv[0] GUICtrlSetData($Combo1,$drv[$i]) Next EndIf EndFunc


×