Jump to content

What is an easier way of doing this?


Recommended Posts

This is a working code, but I just want to know a different and better way of doing this.

$F1 = 'MYPROGRAM1.EXE'
$F2 = 'MYPROGRAM2.EXE'
$F3 = 'MYPROGRAM3.EXE'
$F4 = 'MYPROGRAM4.EXE'
$F5 = 'MYPROGRAM5.EXE'

If Not FileExists($F1) Then
    MsgBox(0, "ERROR", "The file " & $F1 & " is missing.")
    Exit
EndIf
If Not FileExists($F2) Then
    MsgBox(0, "ERROR", "The file " & $F2 & " is missing.")
    Exit
EndIf
If Not FileExists($F3) Then
    MsgBox(0, "ERROR", "The file " & $F3 & " is missing.")
    Exit
EndIf
If Not FileExists($F4) Then
    MsgBox(0, "ERROR", "The file " & $F4 & " is missing.")
    Exit
EndIf
If Not FileExists($F5) Then
    MsgBox(0, "ERROR", "The file " & $F5 & " is missing.")
    Exit
EndIf

Thanks. ;)

Link to comment
Share on other sites

For $x = 1 To 5
 If Not FileExists('MYPROGRAM' & $x & '.EXE') Then
  MsgBox(0, "ERROR", "The file " & 'MYPROGRAM' & $x & '.EXE' & " is missing.")
  Exit
 EndIf
Next

would be another way

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

This is a working code, but I just want to know a different and better way of doing this.

a generic way:

dim $files[4] = ["file1.txt", "file2.txt","file3.txt","file4.txt"]

for $i = 0 to Ubound($files)-1
     if not FileExists($files[$i]) then msgbox(0,"","Missing file: " & $files[$i])
next

Cheers

Kurt

Edited by /dev/null

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

maybe this

$F1 = 'MYPROGRAM1.EXE'
$F2 = 'MYPROGRAM2.EXE'
$F3 = 'MYPROGRAM3.EXE'
$F4 = 'MYPROGRAM4.EXE'
$F5 = 'MYPROGRAM5.EXE'

$F_All = ""

If Not FileExists($F1) Then
    $F_All = $F_All & $F1 & @CRLF
EndIf
If Not FileExists($F2) Then
    $F_All = $F_All & $F2 & @CRLF
EndIf
If Not FileExists($F3) Then
    $F_All = $F_All & $F3 & @CRLF
EndIf
If Not FileExists($F4) Then
    $F_All = $F_All & $F4 & @CRLF
EndIf
If Not FileExists($F5) Then
    $F_All = $F_All & $F5 & @CRLF
EndIf

If $F_All <> "" Then MsgBox(0, "Program Error", "The Following Program Files were Not Found.     " & @CRLF & @CRLF & $F_All)

hope that helps

8)

NEWHeader1.png

Link to comment
Share on other sites

I modified so that the user is prompted with all the files that are missing, instead of only being told of the first missing file:

$MyProgs = 'MYPROGRAM1.EXE|MYPROGRAM2.EXE|MYPROGRAM3.EXE|MYPROGRAM4.EXE|MYPROGRAM5.EXE'
$MyProgsA = StringSplit( $MyProgs, "|")
Dim $Missing = ""

For $i = 1 to $MyProgsA[0]
    If Not FileExists($MyProgsA[$i]) Then
        $Missing = $Missing & $MyProgsA[$i] & ", "
    EndIf
Next
If $Missing <> "" Then
    $Missing = StringLeft($Missing, stringLen($Missing) -2)
    $NumSense = "file is "
    If StringInStr($Missing, ",") Then 
        $NumSense = "files are "
    EndIf
    MsgBox(0, "ERROR", "The following " & $NumSense & "missing: " & $Missing)
    Exit
EndIf
BlueBearrOddly enough, this is what I do for fun.
Link to comment
Share on other sites

a generic way:

dim $files[4] = ["file1.txt", "file2.txt","file3.txt","file4.txt"]

for $i = 0 to Ubound($files)-1
     if not FileExists($files[$i]) then msgbox(0,"","Missing file: " & $files[$i])
next

Cheers

Kurt

need beta for this one i believe

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

need beta for this one i believe

Yep, you're right. Variable initialization does not work that way in the official release. But I'm so used to some nice features of the beta ... ;)

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

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