Anthony Clarke

Anthony Clarke

  • NA
  • 18
  • 36.7k

Please Help - Listing Directory With Directory Size

Feb 21 2012 5:18 AM
Hi,

Im trying to list in a listbox, the directory along with the directory size and wondered whether you could help, can only seem to get the size to list.


FolderBrowserDialog folderBrowerDialog = new FolderBrowserDialog();
folderBrowerDialog.ShowDialog();
string selectedPath = folderBrowerDialog.SelectedPath;
string[] selectedDirectories = Directory.GetDirectories(selectedPath);

long size = 0;

foreach (var dir in selectedDirectories)

{
        string[] files = Directory.GetFiles(dir);

foreach (var file in files)

{

        FileInfo fileInfo = new FileInfo(file);

        size += fileInfo.Length;

}

}






listBox1.Items.Add(size);



Thanks in advance
Anthony

Answers (2)