示例#1
0
        /// <summary>Returns Directory size in Formatted Bytes FileSize Text</summary>
        /// <param name="DirPath">Path of Directory to Return Size</param>
        public static string DirSize(this string DirPath, bool FormatBytes = true)
        {
            // 1.
            // Get array of all file names.
            string[] a = Directory.GetFiles(DirPath, "*.*", System.IO.SearchOption.AllDirectories);

            // 2.
            // Calculate total bytes of all files in a loop.
            long b = 0;

            foreach (string name in a)
            {
                // 3.
                // Use FileInfo to get length of each file.
                FileInfo info = new FileInfo(name);
                b += info.Length;
            }

            string size = b.ToString();

            if (FormatBytes)
            {
                _AHK   ahk   = new _AHK();
                string sizeF = ahk.FormatBytes(b);
                return(sizeF);
            }
            return(b.ToString());
        }