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

arrow
arrow
    全站熱搜

    createps 發表在 痞客邦 留言(0) 人氣()