anzacfalcon Posted November 28, 2009 Share Posted November 28, 2009 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 More sharing options...
Mat Posted November 28, 2009 Share Posted November 28, 2009 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 ahmeddzcom 1 AutoIt Project Listing Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 28, 2009 Moderators Share Posted November 28, 2009 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) NextI take it that you did not want autoit.exe renamed as Flash.exe on your drives, so I altered that bit. I hope that is all clear - please ask if not. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
anzacfalcon Posted November 28, 2009 Author Share Posted November 28, 2009 Thnx so much guys, i really appreciate it! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now