Question

I have information about the output file name only.

enter image description here

How do I get the output size and modification date?

private void button1_Click(object sender, EventArgs e)
{
    FolderBrowserDialog fbd = new FolderBrowserDialog();
    fbd.ShowDialog();
    textBox1.Text = fbd.SelectedPath;
    DirectoryInfo di = new DirectoryInfo(fbd.SelectedPath);
    FileInfo[] files = di.GetFiles();
    DirectoryInfo[] directorys = di.GetDirectories();

    foreach (FileInfo fil in files)
    {
        listView2.Items.Add(fil.Name);
    }
    foreach (DirectoryInfo dir in directorys)
    {
        listView1.Items.Add(dir.Name);
    }
}
Was it helpful?

Solution

All those attributes are on the FileInfo class:

foreach (FileInfo fil in files)
{
    listView2.Items.Add(
        new ListViewItem(
            new string[] {
                fil.Name,
                fil.LastWriteTime.ToString(),
                fil.Length.ToString()
            }
        )
    );
}

OTHER TIPS

File.GetLastWriteTime will get you the last time the file was modified and FileInfo.Length will get you the length of the file if thats what you're looking for.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top