Checking for the existance of 6 files

Wibs

Member
Joined
Jan 16, 2009
Messages
20
Programming Experience
Beginner
Hi,

I have this code for checking if 1 file exists (binPath is already declared):

VB.NET:
Dim filename1 As String = "\OpenSim.Grid.UserServer.exe"
        Dim U As Boolean = System.IO.File.Exists(binPath + filename1)
        If U = False Then
            MessageBox.Show("OpenSim.Grid.UserServer.exe cannot be found in this folder. Please check that this is the correct bin folder, and that the file has not be renamed.", "File not Found", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End If

However, I need to check if another five files exist too. Should I just copy the above code another 5 times, or is there a more efficient way of doing it?

TIA

Wibs
 
Use arraylist...

Use an arraylist to store the file names then loop through the arraylist

VB.NET:
        Dim filArr As New ArrayList
        filArr.Add("File1.exe")
        filArr.Add("File2.exe")
        filArr.Add("File3.exe")
        filArr.Add("File4.exe")
        filArr.Add("File5.exe")

        Dim U As Boolean
        For Each File As String In filArr
            U = System.IO.File.Exists(binPath & "\" & File)
            If U = False Then
                MessageBox.Show(File & " cannot be found in this folder. Please check that this is the correct bin folder, and that the file has not be renamed.", "File not Found", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        Next
 
Many thanks for that alliance. After 5 hours of experimenting I came up with almost the same answer:

VB.NET:
Dim msg As String = vbCrLf
Dim file(5) As String

        file(0) = "OpenSim.Grid.UserServer.exe"
        file(1) = "OpenSim.Grid.GridServer.exe"
        file(2) = "OpenSim.Grid.AssetServer.exe"
        file(3) = "OpenSim.Grid.InventoryServer.exe"
        file(4) = "OpenSim.Grid.MessagingServer.exe"
        file(5) = "OpenSim.exe"

        For n As Integer = 0 To 5
            If System.IO.File.Exists(binPath + "\" + file(n)) = False Then
                msg = msg + file(n) + vbCrLf
            End If
        Next
        MessageBox.Show("The following file(s) could not be found in this folder:" + vbCrLf + msg + vbCrLf + "Please check if it is the correct folder, or if any file has been deleted or renamed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

Wibs
 
Back
Top