I decided to use VB because it will be more versatile for what I want to do.
End result is to enter a computer name, it checks for the existance of files on that PC, and writes the result to a file.
I don't know a good way to roll my If FileExists from the first to last elements in the array.
Here's what I have so far:
Public Class Form1
Public Function FileExists(ByVal Fname As String) As Boolean
'Defines FileExists paramater
If Fname = "" Or (Fname) = "\" Then
FileExists = False : Exit Function
End If
FileExists = (Dir(Fname) <> "")
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Array of files to be queried
Dim backOne() As String = {"Trnhdr.dbf", "Trnhdr.cdx", "Trndtl.dbf", "Trndtl.cdx", "Pohdr.dbf", "Podtl.dbf", "Inwksh.dat", "Indata.dbf", "Indata1.idx", "Indata2.idx", "Vendorwk.dbf", "Vendorwk.cdx", "Vendor.dbf", "Vendor.cdx", "Time.sys", "User.sys", "Comps.mdb"}
'Injected text depending on results
Dim aString As String = " Exists"
Dim bString As String = " Does NOT Exist"
'Defines true and false statements to inject
Dim trueString As String = backOne(1) & aString
Dim falseString As String = backOne(1) & bString
'TextBox1 is the store name
Dim textBox As String = TextBox1.Text
'Path to folder containing files to be queried
Dim aPath As String = "\C$\"
'If Then Else to determin if the files are present
If FileExists("\\" & textBox & aPath & backOne(1)) Then
My.Computer.FileSystem.WriteAllText("H:\logs3\Results.txt", trueString & vbCrLf, True)
Else
My.Computer.FileSystem.WriteAllText("H:\logs3\Results.txt", falseString & vbCrLf, True)
End If
End Sub
End Class
I could just write 16 result string and 16 if then elses but there has to be a slicker way.
Any advice is appreciated.