VB.NET VS2010. Need help with streamreader. Reading all files in the folder one by one.

Hi i need a streamreader to check all the files in the folder. The ones that are let's say TXT and RTF he has to read them one by one and put all the text from each file into one TXT. So basically it will marge all those txt, rtf files.

Thanks.
altimofejevsAsked:
Who is Participating?
 
CodeCruiserCommented:
For txt files

Dim Files As String() = IO.Directory.GetFiles("path", "*.txt")

For Each File In Files
  IO.File.AppenAllLines("TargetFilePath", IO.File.ReadAllLines(File))
Next
0
 
altimofejevsAuthor Commented:
By the way I forgot to mention that the folder is on FTP server
0
 
CodeCruiserCommented:
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
altimofejevsAuthor Commented:
FTP is not too important i can download files to the local computer. What I'm interested in is how to read those files one by one.
0
 
malikirfan28Commented:
You will first need to download all files from FTP and then read these files and merge the files in one file and after that upload the result file on FTP.
So basically you will have to perform following steps.

1. Download files from FTP.
2. Read Files content (StreamReader)
3. Write Files content in a file (using StreamWriter)
4. Upload File on FTP (if Required)

For step 1 and 4, kindly have a look on here.
0
 
CodeCruiserCommented:
RTF files are formatted text. So what you can do is this

Dim RTF As New RichTextBox

Dim RTFFiles As String() = IO.Directory.GetFiles("path", "*.rtf")

For Each File in RTFFiles
   RTF.RTF = IO.File.ReadAllText(File)
   IO.File.AppendAllText("TargetFilePath", RTF.Text)
Next
0
 
altimofejevsAuthor Commented:
before i use readers how can i do something like:

If file-extension = ".txt" then

elseif file-extension = "rtf then

end if
0
 
altimofejevsAuthor Commented:
Also before i read a file I need to make sure that a string exists for example "SOMESTRING"
0
 
CodeCruiserCommented:
Did you try my example?
0
 
malikirfan28Commented:
If you need to check the string content that it constains something and then want to append then you can try this code.
string[] files = System.IO.Directory.GetFiles("Path", "*.txt");
            foreach (string file in files)
            {
                System.IO.StreamReader reader = new System.IO.StreamReader(file);
                string fileContent = reader.ReadToEnd();
                reader.Close();
                if (fileContent.Contains("SOMETHING"))
                    System.IO.File.AppendAllText("destfilePath", fileContent);
            }

Open in new window

0
 
altimofejevsAuthor Commented:
how to show progressbar while downloading files from the FTP server?

So it shows how many files in total are in that folder and % how much left.

Also would be good to know download speed
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.