void 讀取檔案並顯示大小()
{
// Make a reference to a directory.
DirectoryInfo di = new DirectoryInfo("c:\\");
// Get a reference to each file in that directory.
FileInfo[] fiArr = di.GetFiles();
// Display the names and sizes of the files.
Console.WriteLine("The directory {0} contains the following files:", di.Name);
int i = 0;
foreach (FileInfo f in fiArr)
{
ListViewItem LM = new ListViewItem(f.Name);
LM.SubItems.Add(f.Length.ToString());//byte
decimal a = Math.Round((decimal)f.Length / 1024, 5);//K byte
LM.SubItems.Add(a.ToString());
a = Math.Round((decimal)f.Length / (1024 * 1024), 5);//M byte
LM.SubItems.Add(a.ToString());
a = Math.Round((decimal)f.Length / (1024 * 1024 * 1024), 10);//G byte
//a = Math.Round(1073741824m / (1024 * 1024 * 1024), 10);//G byte
LM.SubItems.Add(a.ToString());
this.list.Items.AddRange(new ListViewItem[] { LM });
Console.WriteLine("The size of {0} is {1} bytes.", f.Name, f.Length);
}
}
- Feb 12 Sat 2011 15:52
C# 算出檔案大小從byte到G byte record
全站熱搜
留言列表