I want to get all the files name and their size and save it into an Excel using C#. I have done this but the problem is I want two different column: one for filename and one for Filesize, but my output is saved in one column.
The code I'm using:
public void Main()
{
using (StreamWriter writer = new StreamWriter("D:\\MyFile\\output.csv"))
{
Console.SetOut(writer);
Act();
}
}
static void Act()
{
Console.Write("FileName,".PadRight(20));
Console.WriteLine("Size");
DirectoryInfo di = new DirectoryInfo(@"D:\MyFile");
// Get a reference to each file in that directory.
DataSet ds = new DataSet();
FileInfo[] fiArr = di.GetFiles();
// Display the names and sizes of the files.
//Console.WriteLine("The directory {0} contains the following files:", di.Name);
foreach (FileInfo f in fiArr)
Console.WriteLine("{0}, {1} ", f.Name.PadRight(20), f.Length.ToString());
}
How can I split this into two columns?