pcjunki

if fileexists loop

2 posts in this topic

I have some working code, but I want to know if it can be shortened before It gets to long to edit/maintain

here's what I have, but open to suggestions on how to make it easier to "maintain"

$server1d = "\\server1\d$\file.txt"
$server1e = "\\server1\e$\file.txt"
$server1f = "\\server1\f$\file.txt"
$server1g = "\\server1\g$\file.txt"
$server1i = "\\server1\i$\file.txt"

$server2d = "\\server2\d$\file.txt"
$server2e = "\\server2\e$\file.txt"
$server2f = "\\server2\f$\file.txt"
$server2g = "\\server2\g$\file.txt"
$server2i = "\\server2\i$\file.txt"

If FileExists($server1d) Then

Else
    MsgBox(-1, "server1", "D: drive is down")
    Exit
EndIf







If FileExists($server1e) Then

Else
    MsgBox(-1, "server1", "e: drive is down")
    Exit
EndIf







If FileExists($server1f) Then

Else
    MsgBox(-1, "server1", "f: drive is down")
    Exit
EndIf







If FileExists($server1g) Then

Else
    MsgBox(-1, "server1", "g: drive is down")
    Exit
EndIf







If FileExists($server1i) Then

Else
    MsgBox(-1, "server1", "i: drive is down")
    Exit
EndIf







If FileExists($server2d) Then

Else
    MsgBox(-1, "server2", "D: drive is down")
    Exit
EndIf







If FileExists($server2e) Then

Else
    MsgBox(-1, "server2", "e: drive is down")
    Exit
EndIf







If FileExists($server2f) Then

Else
    MsgBox(-1, "server2", "f: drive is down")
    Exit
EndIf







If FileExists($server2g) Then

Else
    MsgBox(-1, "server2", "g: drive is down")
    Exit
EndIf







If FileExists($server2i) Then

Else
    MsgBox(-1, "server2", "i: drive is down")
    Exit
EndIf

 

Share this post


Link to post
Share on other sites



Use Arrays.

Local $aServers[] = ["\\server1\d$\file.txt", "\\server1\e$\file.txt", "\\server1\f$\file.txt", "\\server1\g$\file.txt", _
        "\\server1\i$\file.txt", "\\server2\d$\file.txt", "\\server2\f$\file.txt", "\\server2\g$\file.txt", "\\server2\i$\file.txt"]



For $i = 0 To UBound($aServers) - 1
    If FileExists($aServers[$i]) Then
    Else
        MsgBox(0, StringMid($aServers[$i], 3, 7), StringUpper(StringMid($aServers[$i], 11, 1)) & ": drive is down")
    EndIf

Next

Saludos

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