/// <summary> /// /// </summary> public static string ObfuscateDirectoryName(string path, int passes = 8) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException(nameof(path)); } if (!Directory.Exists(path)) { throw new DirectoryNotFoundException(path); } { var parent = Directory.GetParent(path).FullName; for (var i = 0; i < passes; i++) { var randName = FileGeneratorHelper.GetRandomNameWithoutExtension(); string combined; while (Directory.Exists(combined = Path.Combine(parent, randName))) { randName = FileGeneratorHelper.GetRandomNameWithoutExtension(); } Directory.Move(path, combined); path = combined; } return(path); } }
/// <summary> /// /// </summary> public static string ObfuscateFileName(string path, int passes = 8) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException(nameof(path)); } if (!File.Exists(path)) { throw new FileNotFoundException(path); } var dir = Path.GetDirectoryName(path); for (var i = 0; i < passes; i++) { var rand = FileGeneratorHelper.GetRandomNameWithoutExtension(); string currentPath; while (File.Exists(currentPath = Path.Combine(dir ?? string.Empty, rand))) { rand = FileGeneratorHelper.GetRandomNameWithoutExtension(); } File.Move(path, currentPath); path = currentPath; } return(path); }