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);
    }
}
Était-ce utile?

La 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()
            }
        )
    );
}

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top