aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Core/Helpers/FileHelper.cs
blob: 8ee0f4b8fefacd01aeb060405136b4e42e087b8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Tango.Core.Helpers
{
    public static class FileHelper
    {
        public static String GetFriendlyFileSize(long fileSize)
        {
            string[] suf = { "B", "KB", "MB", "GB", "TB", "PB", "EB" }; //Longs run out around EB
            if (fileSize == 0)
                return "0" + suf[0];
            long bytes = Math.Abs(fileSize);
            int place = System.Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024)));
            double num = Math.Round(bytes / Math.Pow(1024, place), 1);
            return (Math.Sign(fileSize) * num).ToString() + " " + suf[place];
        }
    }
}