SRFileUtil.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.IO;
  3. using System.Threading;
  4. public static class SRFileUtil
  5. {
  6. public static void DeleteDirectory(string path)
  7. {
  8. try
  9. {
  10. Directory.Delete(path, true);
  11. }
  12. catch (IOException)
  13. {
  14. Thread.Sleep(0);
  15. Directory.Delete(path, true);
  16. }
  17. }
  18. public static string GetBytesReadable(long i)
  19. {
  20. string str = (i >= 0L) ? string.Empty : "-";
  21. double num = (double)((i >= 0L) ? i : (-(double)i));
  22. string str2;
  23. if (i >= 1152921504606846976L)
  24. {
  25. str2 = "EB";
  26. num = (double)(i >> 50);
  27. }
  28. else if (i >= 1125899906842624L)
  29. {
  30. str2 = "PB";
  31. num = (double)(i >> 40);
  32. }
  33. else if (i >= 1099511627776L)
  34. {
  35. str2 = "TB";
  36. num = (double)(i >> 30);
  37. }
  38. else if (i >= 1073741824L)
  39. {
  40. str2 = "GB";
  41. num = (double)(i >> 20);
  42. }
  43. else if (i >= 1048576L)
  44. {
  45. str2 = "MB";
  46. num = (double)(i >> 10);
  47. }
  48. else
  49. {
  50. if (i < 1024L)
  51. {
  52. return i.ToString(str + "0 B");
  53. }
  54. str2 = "KB";
  55. num = (double)i;
  56. }
  57. return str + (num / 1024.0).ToString("0.### ") + str2;
  58. }
  59. }