ref: 一些路径处理
This commit is contained in:
1 parent
ffb79cf1eb
commit
0e8671a7af
2 files changed
+3
-11
No files matched your search
@@ -64,8 +64,8 @@ public static class DirectoryUtils {
|
|||||||
progressHandler?.Invoke(1);
|
progressHandler?.Invoke(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sourceDirName = PathUtils.WithoutLongPath(PathUtils.WithSeparator(sourceDirName, Path.DirectorySeparatorChar));
|
sourceDirName = PathUtils.WithoutLongPath(PathUtils.WithSeparator(sourceDirName)).Replace("/", @"\");
|
||||||
destDirName = PathUtils.WithoutLongPath(PathUtils.WithSeparator(destDirName, Path.DirectorySeparatorChar));
|
destDirName = PathUtils.WithoutLongPath(PathUtils.WithSeparator(destDirName)).Replace("/", @"\");
|
||||||
int doneCount = 0;
|
int doneCount = 0;
|
||||||
Lazy<int> totalCount = new(() => DirectoryUtils.GetFiles(sourceDirName).Count());
|
Lazy<int> totalCount = new(() => DirectoryUtils.GetFiles(sourceDirName).Count());
|
||||||
Logger.Trace($"复制文件夹:{sourceDirName} → {destDirName}");
|
Logger.Trace($"复制文件夹:{sourceDirName} → {destDirName}");
|
||||||
|
|||||||
@@ -9,14 +9,6 @@ public static class PathUtils {
|
|||||||
public static string WithSeparator(string folder)
|
public static string WithSeparator(string folder)
|
||||||
=> folder + (folder.EndsWithF(Path.DirectorySeparatorChar) || folder.EndsWithF(Path.AltDirectorySeparatorChar) ? "" : Path.DirectorySeparatorChar);
|
=> folder + (folder.EndsWithF(Path.DirectorySeparatorChar) || folder.EndsWithF(Path.AltDirectorySeparatorChar) ? "" : Path.DirectorySeparatorChar);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 确保路径使用指定的文件夹分隔符,且末尾包含指定的文件夹分隔符。
|
|
||||||
/// </summary>
|
|
||||||
public static string WithSeparator(string folder, char separator) {
|
|
||||||
folder = folder.Replace(Path.DirectorySeparatorChar, separator).Replace(Path.AltDirectorySeparatorChar, separator);
|
|
||||||
return folder + (folder.EndsWithF(separator) ? "" : separator);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 确保路径的结尾不包含文件夹分隔符。
|
/// 确保路径的结尾不包含文件夹分隔符。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -33,7 +25,7 @@ public static class PathUtils {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static string ToShortPath(string fullName, bool keepFileName = false) {
|
public static string ToShortPath(string fullName, bool keepFileName = false) {
|
||||||
if (string.IsNullOrEmpty(fullName)) return fullName;
|
if (string.IsNullOrEmpty(fullName)) return fullName;
|
||||||
fullName = PathUtils.WithoutLongPath( fullName.Replace('/', '\\'));
|
fullName = PathUtils.WithoutLongPath(fullName.Replace('/', '\\'));
|
||||||
if (fullName.Length <= 200) return fullName;
|
if (fullName.Length <= 200) return fullName;
|
||||||
|
|
||||||
// 保留文件名
|
// 保留文件名
|
||||||
|
|||||||
Reference in new issue
Block a user