Pergunta

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);
    }
}
Foi útil?

Solução

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

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top