Metzen Posted September 17, 2007 Posted September 17, 2007 I'm attempting to check for a file on a all drive letters then set that drive letter as a variable. This is as far as I've gotten: If FileExists ( "C" or "D" or "E" &":\test.txt") then $Drive.Letter=?? else MsgBox (0, "title", "File Not Found" ) EndIf Ideally, I'd like to do this without spanning 26 lines, but if I must then I will. With command prompt scripting I could do the following: FOR %%A IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST %%A:\test SET DRIVE.PATH=%%A But am having difficulty duplicating this in AutoIT. Is it possible?
Valuater Posted September 17, 2007 Posted September 17, 2007 (edited) Welcome to the forums!!! Maybe.... Global $Drive $var = DriveGetDrive( "all" ) If NOT @error Then MsgBox(4096,"", "Found " & $var[0] & " drives") For $i = 1 to $var[0] MsgBox(4096,"Drive " & $i, $var[$i]) If FileExists( $var[$i] & "\whatever.....") Then $Drive = $var[$i] ; do this ExitLoop EndIf Next EndIf Nice try on your first question too!!! 8) Edited September 17, 2007 by Valuater
Metzen Posted September 17, 2007 Author Posted September 17, 2007 Thanks! That worked perfectly. The code I'm going to use is: Global $Drive $var = DriveGetDrive( "all" ) If NOT @error Then For $i = 1 to $var[0] If FileExists( $var[$i] & "\test.txt") Then $Drive = $var[$i] ExitLoop EndIf Next ; uncomment line to verify drive letter MsgBox(4096,"Drive", $Drive) ; insert code here requiring drive letter EndIf
Metzen Posted September 17, 2007 Author Posted September 17, 2007 Thanks! That worked perfectly. The code I'm going to use is: Global $Drive $var = DriveGetDrive( "FIXED" ) If NOT @error Then For $i = 1 to $var[0] If FileExists( $var[$i] & "\test.txt") Then $Drive = $var[$i] ExitLoop EndIf Next ; uncomment line to verify drive letter MsgBox(4096,"Drive", $Drive) ; insert code here requiring drive letter EndIf I had to use FIXED as the scanning would take a few minutes and the program would appear unresponsive if you had a card reader or optical drive.
Valuater Posted September 17, 2007 Posted September 17, 2007 I had to use FIXED as the scanning would take a few minutes and the program would appear unresponsive if you had a card reader or optical drive.Great!!and your welcome!8)
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