StreamReader loop, please help

G

Guest

i am going crazy......
how can i loop through my result set and use File.Copy of File.Move to copy
or move the dim'd filename?????
i have tried AppendAllText, AppendText, Move, Copy, nothing works except the
first file. I understand that the destination must be named, but why can't
the destination name = my variable???

i know it works cuz i used the MsgBox's to verify.......


Imports System.IO
Imports System.Text

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim files As String() = Directory.GetFileSystemEntries("C:\parser")
Dim myfile As String

Dim destfile As Object
destfile = "C:\214\214"
Dim destfile1 As Object
destfile1 = "C:\858\858"

For Each myfile In files

Dim sr As New StreamReader(myfile)
Dim Filecontents As String = sr.ReadToEnd()
Try
If Filecontents.Contains("~214") Then
'File.Copy(myfile, destfile)
MsgBox("214 found")
Else : Filecontents.Contains("ST~858")
'File.Copy(myfile, destfile1)
MsgBox("858 found")
End If
Catch ex As Exception
MsgBox("exception")
End Try
Next
End Sub
End Class
 
G

Guest

geoffa said:
i am going crazy......
how can i loop through my result set and use File.Copy of File.Move to copy
or move the dim'd filename?????
i have tried AppendAllText, AppendText, Move, Copy, nothing works except the
first file. I understand that the destination must be named, but why can't
the destination name = my variable???

i know it works cuz i used the MsgBox's to verify.......


Imports System.IO
Imports System.Text

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim files As String() = Directory.GetFileSystemEntries("C:\parser")
Dim myfile As String

Dim destfile As Object
destfile = "C:\214\214"
Dim destfile1 As Object
destfile1 = "C:\858\858"

For Each myfile In files

Dim sr As New StreamReader(myfile)
Dim Filecontents As String = sr.ReadToEnd()
Try
If Filecontents.Contains("~214") Then
'File.Copy(myfile, destfile)
MsgBox("214 found")
Else : Filecontents.Contains("ST~858")
'File.Copy(myfile, destfile1)
MsgBox("858 found")
End If
Catch ex As Exception
MsgBox("exception")
End Try
Next
End Sub
End Class


i figured it out....

Imports System.IO
Imports System.Text


Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim files As String() = Directory.GetFileSystemEntries("C:\parser")
Dim myfile As String

'Dim destfile As Object
'destfile = "C:\214\214"
'Dim destfile1 As Object
'destfile1 = "C:\858\858"

For Each myfile In files

Dim sr As New StreamReader(myfile)
Dim Filecontents As String = sr.ReadToEnd()
Try
If Filecontents.Contains("~214") Then
Dim puthere As String =
Path.GetFileNameWithoutExtension(myfile)
Dim destfile As Object
destfile = "C:\214\" + puthere
File.Copy(myfile, destfile)
'MsgBox("214 found")

Else : Filecontents.Contains("ST~858")
Dim puthere1 As String =
Path.GetFileNameWithoutExtension(myfile)
Dim destfile1 As Object
destfile1 = "C:\858\" + puthere1
File.Copy(myfile, destfile1)
'MsgBox("858 found")

End If
sr.Close()
Catch ex As Exception
MsgBox("exception")
End Try
Next
End Sub
End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top