Files
BabyVideoService/Utils/FileUtil.cs
2026-02-08 16:58:32 +08:00

44 lines
1012 B
C#

namespace ACBuildService;
public class FileUtil
{
public static readonly string BaseRootPath = $"{AppContext.BaseDirectory}wwwroot/";
public static string GetFileSizeTitle(long length)
{
if (length < 1024)
{
return length + "B";
}
length /= 1024;
if (length < 1024)
{
return (length * 100 / 100) + "KB";
}
length /= 1024;
if (length < 1024)
{
return (length * 100 / 100.0f) + "MB";
}
return ((length / 1024 * 100) / 100.0f) + "GB";
}
/// <summary>
/// 获得文件夹下所有的文件(类库调用)
/// </summary>
/// <param name="dir"></param>
/// <returns></returns>
public static FileInfo[] GetAllFileInfo(DirectoryInfo dir)
{
return dir.GetFiles(".", SearchOption.AllDirectories);
}
public static string GetVideoPath(string fileName)
{
return Path.Combine(BaseRootPath, fileName);
}
}