private static void RemoveFileFromDirectory(Directory dir, File file, string name) { List<string> aliases = new List<string>(); DirectoryEntry dirEntry = dir.GetEntryByName(name); if (dirEntry.Details.FileNameNamespace == FileNameNamespace.Dos || dirEntry.Details.FileNameNamespace == FileNameNamespace.Win32) { foreach (var fnStream in file.GetStreams(AttributeType.FileName, null)) { var fnr = fnStream.GetContent<FileNameRecord>(); if ((fnr.FileNameNamespace == FileNameNamespace.Win32 || fnr.FileNameNamespace == FileNameNamespace.Dos) && fnr.ParentDirectory.Value == dir.MftReference.Value) { aliases.Add(fnr.FileName); } } } else { aliases.Add(name); } foreach (var alias in aliases) { DirectoryEntry de = dir.GetEntryByName(alias); dir.RemoveEntry(de); } }