Jump to content

Recommended Posts

Posted

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?

Posted (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 by Valuater

NEWHeader1.png

Posted

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
Posted

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.

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
×
×
  • Create New...