22 lines
730 B
C#
22 lines
730 B
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace bts.utils {
|
|
public static class FilePathHelper {
|
|
public static string GetUniquePathWithDate(string path_root, string ext) =>
|
|
GetUniquePath($"{path_root}_{DateTime.Now:MM - dd - yyyy_hh - mm}", ext);
|
|
|
|
public static string GetUniquePath(string path_root, string ext) {
|
|
var path = $"{path_root}.{ext}";
|
|
const int max_copies = 2 ^ 14;
|
|
int i = 1;
|
|
while (File.Exists(path)) {
|
|
path = $"{path_root}({i++}).{ext}";
|
|
if (i == max_copies)
|
|
throw new InvalidOperationException("Unable to make path unique by concating a number.");
|
|
}
|
|
return path;
|
|
}
|
|
}
|
|
}
|