Hi All,
I have a folder, here's the folder tree:
\---DC20120127-00000831
\---PABO20120127000017
\---AT
| V20.txt
| V23.txt
|
+---2012033
| 00000002_00000000.tif
| 00000003_00000000.tif
| 00000004_00000000.tif
| 00000005_00000000.tif
|
\---INVALID IMAGES
00000001_.tif
00000002_00000001.tif
00000003_00000001.tif
00000004_00000001.tif
00000005_00000001.tif
I have coded a program that will compare if the total count of tif in folder 2012033 (2012033 is the combination of year and dayofyear) is equal to the total count of ".tif" string found in V20.txt and V23.txt.
Here's my code so far:
Public Class Form1
Dim openFolder As New FolderBrowserDialog
Private Sub btnValidate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnValidate.Click
Try
ListView1.Items.Clear()
openFolder.RootFolder = Environment.SpecialFolder.MyComputer
If openFolder.ShowDialog() = Windows.Forms.DialogResult.OK Then
For Each Dir As String In Directory.GetDirectories(openFolder.SelectedPath)
Dim intPos As Integer
intPos = Dir.LastIndexOfAny("\")
intPos += 1
Dim strName As String = Dir.Substring(intPos, (Len(Dir) - intPos))
If GetCountTxt(Dir) <> GetTifCount(Dir & "\" & cLab.Text & "\" & DateTime.Now.Year & String.Format("{0:000}", DateTime.Now.DayOfYear)) Then
Dim str(6) As String
Dim itm As ListViewItem
str(0) = openFolder.SelectedPath
str(1) = strName
str(2) = "1"
str(3) = "1"
str(4) = "Unmatched count of tif in text vs. count of tif in folder, please check!"
str(5) = "Count in text: " & GetCountTxt(Dir) & " <---> " & "Count in folder: " & GetTifCount(Dir & "\" & cLab.Text & "\" & DateTime.Now.Year & String.Format("{0:000}", DateTime.Now.DayOfYear))
itm = New ListViewItem(str)
ListView1.Items.Add(itm)
End If
Next
MessageBox.Show("Done Edit Checking!", "Information Box", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Public Function GetTifCount(ByVal strPath As String) As Integer
Try
Return Directory.GetFiles(strPath, "*.TIF", SearchOption.AllDirectories).Length()
Catch ex As Exception
Dim str(6) As String
Dim itm As ListViewItem
str(0) = strPath
str(1) = strPath
str(2) = "N/A"
str(3) = "N/A"
str(4) = "Day of the year is not set to current, please check the folder name of valid tif files. This should be " & DateTime.Now.Year & String.Format("{0:000}", DateTime.Now.DayOfYear)
str(5) = ""
itm = New ListViewItem(str)
ListView1.Items.Add(itm)
Throw New Exception("Critical error, please check the on-screen error.", ex)
End Try
End Function
Public Function GetCountTxt(ByVal strPath As String) As Integer
Try
Dim fileEntries As String() = Directory.GetFiles(strPath, "*.txt", SearchOption.AllDirectories)
' Process the list of .txt files found in the directory. '
Dim fileName As String
Dim tcount As Integer = 0
For Each fileName In fileEntries
Dim basa As New StreamReader(fileName)
While Not basa.EndOfStream
Dim law As String = basa.ReadLine()
If law.ToLower.Contains(".tif") Then
tcount += 1
End If
End While
Next
Return tcount
Catch ex As Exception
Throw New Exception("Error From GetCountTxt Function" & ex.Message, ex)
End Try
End Function
End Class
The problem is that the result is always unmatched because the filename of tif from folder 2012033 was used in V20.txt and V23.txt. For example, string "00000002_00000000.tif" is present in V20.txt as well as in V23.txt that's why I can't accurately match them. What should be my work around here?
Is there a way to simplify my code? I'm sorry I'm just starting to learn vb.net 2010.
I've attached my input files here for your reference.
Thanks in advance.