using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Common.Helper.Nlog;
namespace Common.Helper.File
{
public class FileHelper
{
///
/// 创建文件夹
///
///
public static void CreateFile(string file)
{
if (Directory.Exists(file))
//文件夹已经存在
return;
try
{
Directory.CreateDirectory(file);
//创建成功
}
catch (Exception e)
{
LogHelper.Log.Error($"文件创建出错:{e.ToString()}");
}
}
///
/// 获取文件大小
///
/// 文件长度
///
public static string FileSize(long length)
{
var unit = new List() { "K", "M", "G" };
var size = Math.Round(length / 1024.0, 2);
var index = 0;
while (size > 1024 && index < 2)
{
index++;
size = Math.Round(size / 1024, 2);
}
return $"{size}{unit[index]}";
}
}
}