Suppose we have 3 text files that will be called, for example, one.txt, two.txt, and three.txt. The number 100 is written in the file one.txt. In the file two.txt - 15. And in three.txt - 60 How can I display the names of these files (along with .txt) and their contents in this format:
one.txt - 100 two.txt - 15 three.txt - 60
I found the code, but it displays only the contents of the files, I just can’t make it so that along with this content the name of the file in which it is displayed
var fileStorage = new List<string[]>(); string path = @"..." string[] promoDir = Directory.GetFiles(path); try { var filePaths = Directory.GetFiles(path); //string[] foreach (string path in filePaths) { string[] fileLines = System.IO.File.ReadAllLines(path); fileStorage.Add(fileLines); } foreach (string[] fileLines in fileStorage) { foreach (string fileLine in fileLines) { Console.WriteLine(); } }
Thank you in advance!