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);
    }
}
有帮助吗?

解决方案

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top