1-) C# Athena - dosya boyutu mb gb file size
public string MyGetSize(string pDosyaYolu) {
string[] sizes = { "B", "KB", "MB", "GB", "TB" };
double len = new FileInfo(pDosyaYolu).Length;
int order = 0;
while (len >= 1024 && order < sizes.Length - 1) {
order++;
len = len / 1024;
}
string result = String.Format("{0:0.##} {1}", len, sizes[order]);
//bayt
long length = new FileInfo(pDosyaYolu).Length;
string uzunluk = string.Format("{0:n0}", length) + " bayt";
string hepsi=result+" ("+uzunluk+")";
//bayt
return hepsi;
}
2-) dizin(klasör) boyutu mb gb file size
string[] sizes = { "B", "KB", "MB", "GB", "TB" };
string hepsi = "hesaplanacak";
DirectoryInfo di = new DirectoryInfo(pDosyaYolu);
long len = di.EnumerateFiles("*.*", SearchOption.AllDirectories).Sum(fi => fi.Length);
int order = 0;
while (len >= 1024 && order < sizes.Length - 1) {
order++;
len = len / 1024;
}
string result = String.Format("{0:0.##} {1}", len, sizes[order]);
//bayt
long len1 = di.EnumerateFiles("*.*", SearchOption.AllDirectories).Sum(fi => fi.Length);
string uzunluk = string.Format("{0:n0}", len1) + " bayt";
hepsi = "[" + result + " (" + uzunluk + ")]";
//bayt
3-) dikkat
DirectoryInfo -> (dizin) klasör
FileInfo -> dosya