public void RenameItem(string source, string newName) { ThrowIfDisposed(); using (ComReleaser <IShellItem> sourceItem = CreateShellItem(source)) { _fileOperation.RenameItem(sourceItem.Item, newName, null); } }
public static void Move(string destination, string source, bool overwrite = true) { if (Path.GetFullPath(destination) == Path.GetFullPath(source)) { return; } if (!overwrite) { destination = GetNonOverwriteFilename(destination); } if (_fileOperation == null) { System.IO.File.Move(source, destination); } else { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && string.Equals(destination, source, StringComparison.CurrentCultureIgnoreCase)) { System.IO.File.Move(destination + " ", source); source = destination + " "; } var sourceItem = CreateItem(source); long result; if (Path.GetDirectoryName(source) != Path.GetDirectoryName(destination)) { var destinationPathItem = CreateItem(Path.GetDirectoryName(destination)); result = _fileOperation.MoveItem(sourceItem, destinationPathItem, Path.GetFileName(destination), IntPtr.Zero); Marshal.ReleaseComObject(destinationPathItem); } else { result = _fileOperation.RenameItem(sourceItem, Path.GetFileName(destination), IntPtr.Zero); } Marshal.ReleaseComObject(sourceItem); AssertHresult(result); } }
//public HResult ApplyPropertiesToItems(object punkItems) //{ // throw new NotImplementedException(); //} public void RenameItem(IShellItem psiItem, string pszNewName, FileOperationProgressSink pfopsItem) { if (disposed) { throw new ObjectDisposedException(nameof(FileOperation)); } HResult hr = fileOperation.RenameItem(psiItem, pszNewName, pfopsItem?.FileOperationProgressSinkInternal); if (!CoreErrorHelper.Succeeded(hr)) { Marshal.ThrowExceptionForHR((int)hr); } }
public void RenameItem(string source, string newName) { ThrowIfDisposed(); using var sourceItem = CreateShellItem(source); _fileOperation.RenameItem(sourceItem.Item, newName, null); }
public void RenameItem(string source, string newName) { IShellItem sourceItem = SafeNativeMethods.CreateShellItem(source); fileOperation.RenameItem(sourceItem, newName, null); }