Domanda

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);
    }
}
È stato utile?

Soluzione

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

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top