473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

StreamReader loop, please help

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
Apr 6 '07 #1
1 1655


"geoffa" wrote:
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
Apr 6 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Andy Mee | last post by:
Hello one and all, I'm developing an Asp.NET system to take a CSV file uploaded via the web, parse it, and insert the values into an SQL database. My sticking point comes when I try to split()...
7
by: BlueOysterCult | last post by:
Hello all I have a project that I have to read the file - which I have done I can see the file output. I then need to read the line - parse the line into three separate values (there are 3 = name...
5
by: Anders Olsson | last post by:
I need to create a StreamReader which starts from the position of an existing StreamReader. This way, the second StreamReader can read lines "ahead" in an own loop, and then I can go back to the...
1
by: Tarren | last post by:
Hi: Question which might have something to do with encoding? I have a text file and I use the following code to iterate through. StreamReader oStreamFile = new StreamReader(sFileName); ...
2
by: James Wong | last post by:
Dear all, I'm using StreamReader to read a text file containing BIG-5 data and found that no matter which encoding method in StreamReader's construction parameter, the BIG-5 contents become...
2
by: Mr Dutchie | last post by:
Hello, For some reason, my program is locking up on the "New Streamreader(fs)" part in my program.. I doublechecked everything but nothing is changed since the last time I worked on it. and...
5
by: =?Utf-8?B?V2lsbGlhbSBGb3N0ZXI=?= | last post by:
Good evening all, I am trying to write a process that uses a while loop to cycle multiple files from an array throught the StreamReader Process. The whole thing works using: Dim...
5
by: Dave Bootsma | last post by:
I have an application where I want to redraw a polygon from points I retrieve from a file. The file is read with streamreader line by line each line contains the points for each polygon. Below is...
3
by: =?Utf-8?B?Qm9zc2ll?= | last post by:
Hi All, I am having a little trouble with a StreamReader. I am currently reading a pipe delimited file with around 1.8 million records (total size 150MB) and, based on a flag, insert update or...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.