Link to home
Start Free TrialLog in
Avatar of altimofejevs
altimofejevs

asked on

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.
Avatar of altimofejevs
altimofejevs

ASKER

By the way I forgot to mention that the folder is on FTP server
Avatar of Nasir Razzaq
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.
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.
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
before i use readers how can i do something like:

If file-extension = ".txt" then

elseif file-extension = "rtf then

end if
Also before i read a file I need to make sure that a string exists for example "SOMESTRING"
Did you try my example?
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

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