K
Keith Kowalski
I anm opening up a text file reading the lines of the file that refer to a
tif image in that file, If the tif image does not exist I need it to send an
email stating that the file doesn't exist then skip this file and move onto
the next file (line).
If file is there then move to a sirectory.
Here is the code I have (Feel free to make corrections as needed. If
possible make changes in red)
'Most Declarations are made as Public String or integer
Dim oDirInfo As DirectoryInfo = New DirectoryInfo(strPath) 'Sets path to
Print Folder
Dim oFiles() As FileInfo = oDirInfo.GetFiles 'Gets File list
from Print Folder
Dim oFile As FileInfo
For Each oFile In oDirInfo.GetFiles
'Gets only files that have an 'lst' extension
If oFile.Name.Substring(oFile.Name.Length - 3) = "lst" Then
'Adds the .lst file to the Listbox(1) along with the
path
ListBox1.Items.Add(strPath + oFile.Name)
strBatch = parseFileName(oFile.Name)
lblBatch.Text = "Batch: " & strBatch
lblBatch.Refresh()
'Sets strTPath as ListBox1.Items(0)
Dim strTPath As String = ListBox1.Items(0) 'IE:
atl26E_Batch.lst
'Show The Selected Item (0)
ListBox1.SelectedIndex = 0
'Sets StreamReader to Read Lines of the lst File
'strTPath is the first Item in ListBox1
Dim objStreamReader As System.IO.StreamReader = New
StreamReader(strTPath)
'Read to end of file or blank line
Do Until objStreamReader.Peek = -1
Try
strLine = objStreamReader.ReadLine()
' Exit the Loop if line is blank, signaling end
of file
If strLine = "" Then
Exit Do
Else
'myString equals the Line of Text from lst
File
Dim myString As String = strLine
'Filename.tif
' Remove Quotes (") From a string
strLine =
strLine.Replace(ControlChars.Quote, String.Empty)
'Puts location of file and line text (Image
Name) into ListBox2
'ie: C:\printImages\07162004\
atl26E_Batch\Image1.tif
ListBox2.Items.Add(strPrintFolder & strLine)
'Wait 1 second(s) for process to catch up
Thread.Sleep(1000)
'Keep count of number of images into
ListBox2
xCount = xCount + 1
'Refresh Listbox2 to display current Images
ListBox2.Refresh()
End If
Catch ex As Exception 'Not in correct Location
'Catch the error and display it.
strErrorMessage = "The following InnerException
reported: " & _
ex.InnerException.ToString()
'MessageBox.Show(IOExp.ToString)
MessageBox.Show(ex.ToString)
MessageBox.Show(ex.Message)
Emailit(strErrorMessage)
Exit Sub
End Try
Loop 'End Do Until loop
'Close StreamReader
objStreamReader.Close() 'Close the Streamreader
objStreamReader = Nothing 'Set Streamreader to Nothing
'***********************************************************************
'>>> Create Directory for lst file and move to that
directory >>>
'***********************************************************************
Dim strOfileName As String = oFile.Name
'Remove ".lst" From the File name
Dim strRemovelst As String =
strOfileName.Replace(".lst", String.Empty)
'set archive folder name + "d" + Date + File Naem -
".lst"
strMyDir = strArchiveFolder + "d" + myDateReplace +
strRemovelst
Dim strSubDir As String = strArchiveFolder +
myDateReplace + strRemovelst
Dim strCSubDir As String = strArchiveFolder +
myDateReplace + "\" + strRemovelst + "\"
' Make a reference to a directory.
Dim di As New DirectoryInfo(strArchiveFolder +
myDateReplace)
' Create the directory only if it does not already
exist.
If di.Exists = False Then
di.Create()
End If
' Create a subdirectory in the directory just created.
Dim dis As DirectoryInfo =
di.CreateSubdirectory(strRemovelst)
If dis.Exists = False Then
dis.Create()
'Move files to this directory
'Dim lstFileMove As FileInfo = New FileInfo(strPath
+ oFile.Name)
'lstFileMove.MoveTo(strCSubDir + strRemovelst +
".lst")
Else
'Move files to this directory
Dim lstFileMove As FileInfo = New FileInfo(strPath +
oFile.Name)
lstFileMove.MoveTo(strCSubDir + strRemovelst +
".lst")
End If
'Print Images, GoTO PrintImages Sub
' Calls a sub to print the images
PrintImages(strCSubDir, strRemovelst)
iCount = iCount + 1 'Keep track of
Images
ListBox2.Items.Clear() 'Clear the
Listbox(2)
End If
Next 'End For Next Loop
oFile = Nothing 'Set oFile to Nothing
ListBox1.Items.Clear() 'Clear Listbox(1)
ListBox2.Items.Clear() 'Clear Listbox(2)
lblBatch.Text = "Batch: "
Timer1.Enabled = True 'Re-Enable the Timer (Starts
code from beginning)
End If
tif image in that file, If the tif image does not exist I need it to send an
email stating that the file doesn't exist then skip this file and move onto
the next file (line).
If file is there then move to a sirectory.
Here is the code I have (Feel free to make corrections as needed. If
possible make changes in red)
'Most Declarations are made as Public String or integer
Dim oDirInfo As DirectoryInfo = New DirectoryInfo(strPath) 'Sets path to
Print Folder
Dim oFiles() As FileInfo = oDirInfo.GetFiles 'Gets File list
from Print Folder
Dim oFile As FileInfo
For Each oFile In oDirInfo.GetFiles
'Gets only files that have an 'lst' extension
If oFile.Name.Substring(oFile.Name.Length - 3) = "lst" Then
'Adds the .lst file to the Listbox(1) along with the
path
ListBox1.Items.Add(strPath + oFile.Name)
strBatch = parseFileName(oFile.Name)
lblBatch.Text = "Batch: " & strBatch
lblBatch.Refresh()
'Sets strTPath as ListBox1.Items(0)
Dim strTPath As String = ListBox1.Items(0) 'IE:
atl26E_Batch.lst
'Show The Selected Item (0)
ListBox1.SelectedIndex = 0
'Sets StreamReader to Read Lines of the lst File
'strTPath is the first Item in ListBox1
Dim objStreamReader As System.IO.StreamReader = New
StreamReader(strTPath)
'Read to end of file or blank line
Do Until objStreamReader.Peek = -1
Try
strLine = objStreamReader.ReadLine()
' Exit the Loop if line is blank, signaling end
of file
If strLine = "" Then
Exit Do
Else
'myString equals the Line of Text from lst
File
Dim myString As String = strLine
'Filename.tif
' Remove Quotes (") From a string
strLine =
strLine.Replace(ControlChars.Quote, String.Empty)
'Puts location of file and line text (Image
Name) into ListBox2
'ie: C:\printImages\07162004\
atl26E_Batch\Image1.tif
ListBox2.Items.Add(strPrintFolder & strLine)
'Wait 1 second(s) for process to catch up
Thread.Sleep(1000)
'Keep count of number of images into
ListBox2
xCount = xCount + 1
'Refresh Listbox2 to display current Images
ListBox2.Refresh()
End If
Catch ex As Exception 'Not in correct Location
'Catch the error and display it.
strErrorMessage = "The following InnerException
reported: " & _
ex.InnerException.ToString()
'MessageBox.Show(IOExp.ToString)
MessageBox.Show(ex.ToString)
MessageBox.Show(ex.Message)
Emailit(strErrorMessage)
Exit Sub
End Try
Loop 'End Do Until loop
'Close StreamReader
objStreamReader.Close() 'Close the Streamreader
objStreamReader = Nothing 'Set Streamreader to Nothing
'***********************************************************************
'>>> Create Directory for lst file and move to that
directory >>>
'***********************************************************************
Dim strOfileName As String = oFile.Name
'Remove ".lst" From the File name
Dim strRemovelst As String =
strOfileName.Replace(".lst", String.Empty)
'set archive folder name + "d" + Date + File Naem -
".lst"
strMyDir = strArchiveFolder + "d" + myDateReplace +
strRemovelst
Dim strSubDir As String = strArchiveFolder +
myDateReplace + strRemovelst
Dim strCSubDir As String = strArchiveFolder +
myDateReplace + "\" + strRemovelst + "\"
' Make a reference to a directory.
Dim di As New DirectoryInfo(strArchiveFolder +
myDateReplace)
' Create the directory only if it does not already
exist.
If di.Exists = False Then
di.Create()
End If
' Create a subdirectory in the directory just created.
Dim dis As DirectoryInfo =
di.CreateSubdirectory(strRemovelst)
If dis.Exists = False Then
dis.Create()
'Move files to this directory
'Dim lstFileMove As FileInfo = New FileInfo(strPath
+ oFile.Name)
'lstFileMove.MoveTo(strCSubDir + strRemovelst +
".lst")
Else
'Move files to this directory
Dim lstFileMove As FileInfo = New FileInfo(strPath +
oFile.Name)
lstFileMove.MoveTo(strCSubDir + strRemovelst +
".lst")
End If
'Print Images, GoTO PrintImages Sub
' Calls a sub to print the images
PrintImages(strCSubDir, strRemovelst)
iCount = iCount + 1 'Keep track of
Images
ListBox2.Items.Clear() 'Clear the
Listbox(2)
End If
Next 'End For Next Loop
oFile = Nothing 'Set oFile to Nothing
ListBox1.Items.Clear() 'Clear Listbox(1)
ListBox2.Items.Clear() 'Clear Listbox(2)
lblBatch.Text = "Batch: "
Timer1.Enabled = True 'Re-Enable the Timer (Starts
code from beginning)
End If