• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 601
  • Last Modified:

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.
0
altimofejevs
Asked:
altimofejevs
  • 5
  • 4
  • 2
1 Solution
 
altimofejevsAuthor Commented:
By the way I forgot to mention that the folder is on FTP server
0
 
CodeCruiserCommented:
0
 
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
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
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:
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
 
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

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now