| 12345678910111213141516171819202122232425262728293031 |
- using MeloongCore.Extensions;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MeloongCore;
- public static class DirectoryUtils {
- /// <summary>
- /// 确保路径以 / 或 \ 结尾。
- /// </summary>
- public static string ToDirectoryFormat(string folder) => IsDirectoryFormat(folder) ? folder : folder + Path.DirectorySeparatorChar;
- /// <summary>
- /// 检查路径是否以 / 或 \ 结尾。
- /// </summary>
- public static bool IsDirectoryFormat(string path) => path.EndsWithF("/") || path.EndsWithF("\\");
- /// <summary>
- /// 创建文件夹,或文件所在的文件夹。
- /// 支持长路径,文件夹已存在时不会抛出异常。
- /// </summary>
- public static void Create(string path, bool isFilePath = false) {
- if (isFilePath) path = Path.GetDirectoryName(path);
- Directory.CreateDirectory(PathUtils.Shorten(path));
- }
- }
|