private static string GetMtpPath(string executable) { if (executable.StartsWith("\\\\?\\")) { using var computer = new ShellFolder(Shell32.KNOWNFOLDERID.FOLDERID_ComputerFolder); using var device = computer.FirstOrDefault(i => executable.Replace("\\\\?\\", "").StartsWith(i.Name)); var deviceId = device?.ParsingName; var itemPath = Regex.Replace(executable, @"^\\\\\?\\[^\\]*\\?", ""); return(deviceId != null?Path.Combine(deviceId, itemPath) : executable); } return(executable); }
public void MoveItemTest() { // Delete item to Recycle Bin using var tmp = new TempFile(); Assert.That(() => ShellFileOperations.Delete(tmp.FullName), Throws.Nothing); // Find deleted item using var bin = new ShellFolder(KNOWNFOLDERID.FOLDERID_RecycleBinFolder); var item = bin.FirstOrDefault(si => si.Name == tmp.FullName); Assert.NotNull(item); // Restore item using var dest = new ShellFolder(Path.GetDirectoryName(tmp.FullName)); Assert.That(() => ShellFileOperations.Move(item, dest, null, ShellFileOperations.OperationFlags.NoConfirmation), Throws.Nothing); Assert.IsTrue(File.Exists(tmp.FullName)); }