none
C# how to read all text file in folder and create new text file RRS feed

  • Question

  • hii all, i have a problem i write the code for read all (.HBY) text file from folder and create one new file but only one text file that read. someone please help me.

    this is my code :

    string datetime = DateTime.Now.ToString("MMdd");
                string path = @"c:\ombi\0111"+datetime+".HBY";
                string FileExtension = ".HBY";
                string DestinationFolder = @"C:\ombi\";
                string FileDelimiter = ","; //You can prov
    
                // string[] array2 = Directory.GetFiles(@"C:\ombi\test","*HBY");
                // foreach (string fileName in array2)
                //foreach (string fileName in Directory.GetFiles(@"C:\ombi\test", "*.HBY"))
                foreach (var file in
                 Directory.GetFiles(@"C:\\ombi\\test", "*.HBY"))
                {
                    if (!File.Exists(path))
                     {
                            using (StreamWriter sw = File.CreateText(path))
                         {
                            string fileLines = File.ReadAllText(file);
                            sw.Write(fileLines);
                        }
                     }
                }
                using (StreamReader sr = File.OpenText(path))
                {
                    string s = "";
                    while ((s = sr.ReadLine()) != null)
                    {
                        Console.Write(s);
                    }
                }
            }

    Monday, April 30, 2018 3:54 AM

Answers