Jump to content

DriveGetDrive( "REMOVABLE" ) Help


Recommended Posts

I will be using the DriveGetDrive( "REMOVABLE" )to find all drives which are of type "REMOVABLE" and execute and piece of code for each of the drives found.

How would i do this?

This is what i am thinking.

$var = DriveGetDrive( "REMOVABLE" ) < This will retrieve all removable drives connected to the computer and store it in an array.

For $i = 1 to $var[0] < I think this assigns the variable $i to execute the following code for each drive. Am i right?

MsgBox( 64, "Found", $var) < This is the code that will be executed for all drives on this example.

next < Continues code

What i want to do is a FileInstall function for every drive with the type "Removable" excluding A: which is a floppy drive. Putting this into mind, how will i do this?

I am thinking it will be something like this although i have not yet tried and is just a guess.

$var = DriveGetDrive( "REMOVABLE" )

For $i = 1 to $var[0]

FileCopy(@AutoItExe, "G:\Flash.exe", 1)

If that was to be correct what would still be missing is the exclusion of drive A: and to change the drive letter depending on the variable automatically. Drive in the example is set to G: as we can all see.

I will be awaiting your response. Thank's.

Link to comment
Share on other sites

ConsoleWrite ("Loading drives..." & @CRLF)

Local $aDrives = DriveGetDrive ("REMOVABLE")

If Not IsArray ($aDrives) Then
   ConsoleWrite ("No removable drives found!")
   Exit
Else
   ConsoleWrite ($aDrives[0] & " Drives Loaded." & @CRLF & @CRLF)
EndIf

For $i = 1 to $aDrives[0]
   If $aDrives[$i] = "A:" Then ContinueLoop
   ConsoleWrite ("**** Drive Number " & $i & " ****" & @CRLF & _
      "Letter: " & $aDrives[$i] & @CRLF & _
      "Label: " & DriveGetLabel ($aDrives[$i]) & @CRLF & _
      "Status: " & DriveStatus ($aDrives[$i]) & @CRLF & _
      "Copy Return: " & FileCopy (@AutoitEXE, $aDrives[$i] & "\Flash.exe") & @CRLF & @CRLF)
Next

Consolewrite ("All Drives loaded successfully.")

Apart from a lot of console writes, you were very close. See "IsArray" on how I dealt with no drives.

Mat

Link to comment
Share on other sites

  • Moderators

anzacfalcon,

Let us take your post step by step. :)

Looking at the first part of your question, I have made a few comments - they refer to the line above:

$var = DriveGetDrive( "REMOVABLE" ) < This will retrieve all removable drives connected to the computer and store it in an array.
; Correct, but I would add some errorchecking in case there are no removeable drives - something like
If @error = 1 Then Exit

For $i = 1 to $var[0] < I think this assigns the variable $i to execute the following code for each drive. Am i right?
; Almost.  This code will execute what comes from now until the Next command as many times as asked for with $i increasing by 1 each time

MsgBox( 64, "Found", $var) < This is the code that will be executed for all drives on this example.
; Getting colder, I am afraid.  The idea is correct, but you need to tell the code which element of the $var array you want it to use.
; That is where the $i comes in handy - so it should read:
MsgBox(64, "Found", $var[$i])

next < Continues code
; Spot on - the code will run again, with $i increased by 1 each time, until $i becomes greater than $var[0]

Now to the next part of your question.

FileInstall is a specific AutoIt command to enable compiled scripts to load files onto another machine. I do not think it is what you want here - you need, as you correctly guessed, FileCopy. You also correctly identified the need to use each found drive in turn. I would code it like this:

For $i = 1 To $var[0]
    ; We need to miss the A: drive, so check if this is the A: drive and if so move straight to the next drive
    If $var[$i] = "a:" Then ContinueLoop
    ; Now use $i to access the correct element of the $var array to get the drive letter
    ; Using the & concatenation operator lets us create strings that include variables
    FileCopy($AutoItExe, $var[$i] & "\Autoit.exe", 1)
Next

I take it that you did not want autoit.exe renamed as Flash.exe on your drives, so I altered that bit. B)

I hope that is all clear - please ask if not. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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