Multiple files

gerlatie

New member
Joined
Mar 1, 2016
Messages
3
Programming Experience
Beginner
How can i process more then one file.
There are three files PC1_456454_test_544.csv, PC8_546545_test_54564.csv and PC10_sdfds_test_56464.csv
All the those three files must be processed and added in "Barcodes.txt"

        static void Main(string[] args)
        {
            string path = @"c:";
            string fileName = "PC1" + "*" + "test" + "*" + ".csv";
            string[] files = System.IO.Directory.GetFiles(path, fileName);
            string datetime = DateTime.Now.ToString("_yyMMdd");
            string read ="";
            string barcode = "";
            string barcode3s = "";


            DirectoryInfo di = new DirectoryInfo(path);
            FileInfo[] Files = di.GetFiles(fileName);


                        using (StreamReader reader = new StreamReader(files[0]))
                        using (StreamWriter write = new StreamWriter(path + "Barcodes.txt", false, Encoding.GetEncoding(1250)))
                    do
                    {
                        read = reader.ReadLine();
                        if (read != null)
                        {
                            if (read.Substring(0, 2) == "80")
                                {
                                        barcode = read.Substring(5, 24);
                                        barcode3s = read.Substring(36);
                                        int lengtebarcode3s = barcode3s.Length;
                                        int lengtespace = 40 - lengtebarcode3s;
                                        string schrijvenbarcode3s = barcode3s + new string(' ', lengtespace);
                                        write.WriteLine(schrijvenbarcode3s + barcode);
                                }
                        }
                    } while (read != null);
        }
 
Last edited by a moderator:
How do you usually perform an action multiple times? With a loop. In this case, the obvious choice is a 'foreach' loop.
var files = myDirectoryInfo.GetFiles(pattern);

foreach (var file in files)
{
    // Use file here.
}
 
Back
Top Bottom