using System; using System.IO; using System.Runtime.InteropServices; namespace Vanara.PInvoke { public static partial class Shell32 { /// Flags that control the file operation. [PInvokeData("Shobjidl.h")] [Flags] public enum FILEOP_FLAGS : uint { /// /// The pTo member specifies multiple destination files (one for each source file in pFrom) rather than one directory where all /// source files are to be deposited. /// FOF_MULTIDESTFILES = 0x0001, /// Not implemented. [Obsolete] FOF_CONFIRMMOUSE = 0x0002, /// Do not display a progress dialog box. FOF_SILENT = 0x0004, /// /// Give the item being operated on a new name in a move, copy, or rename operation if an item with the target name already exists. /// FOF_RENAMEONCOLLISION = 0x0008, /// Respond with Yes to All for any dialog box that is displayed. FOF_NOCONFIRMATION = 0x0010, /// /// If FOF_RENAMEONCOLLISION is specified and any files were renamed, assign a name mapping object that contains their old and /// new names to the hNameMappings member. This object must be freed using SHFreeNameMappings when it is no longer needed. /// FOF_WANTMAPPINGHANDLE = 0x0020, /// /// Preserve undo information, if possible. /// Prior to Windows Vista, operations could be undone only from the same process that performed the original operation. /// /// In Windows Vista and later systems, the scope of the undo is a user session. Any process running in the user session can undo /// another operation. The undo state is held in the Explorer.exe process, and as long as that process is running, it can /// coordinate the undo functions. /// /// If the source file parameter does not contain fully qualified path and file names, this flag is ignored. /// FOF_ALLOWUNDO = 0x0040, /// Perform the operation only on files (not on folders) if a wildcard file name (*.*) is specified. FOF_FILESONLY = 0x0080, /// Display a progress dialog box but do not show individual file names as they are operated on. FOF_SIMPLEPROGRESS = 0x0100, /// Do not confirm the creation of a new folder if the operation requires one to be created. FOF_NOCONFIRMMKDIR = 0x0200, /// /// Do not display a message to the user if an error occurs. If this flag is set without FOFX_EARLYFAILURE, any error is treated /// as if the user had chosen Ignore or Continue in a dialog box. It halts the current action, sets a flag to indicate that an /// action was aborted, and proceeds with the rest of the operation. /// FOF_NOERRORUI = 0x0400, /// Do not copy the security attributes of the item. FOF_NOCOPYSECURITYATTRIBS = 0x0800, /// Only operate in the local folder. Do not operate recursively into subdirectories. FOF_NORECURSION = 0x1000, /// Do not move connected items as a group. Only move the specified files. FOF_NO_CONNECTED_ELEMENTS = 0x2000, /// /// Send a warning if a file or folder is being destroyed during a delete operation rather than recycled. This flag partially /// overrides FOF_NOCONFIRMATION. /// FOF_WANTNUKEWARNING = 0x4000, FOF_NORECURSEREPARSE = 0x8000, /// /// Walk into Shell namespace junctions. By default, junctions are not entered. For more information on junctions, see Specifying /// a Namespace Extension's Location. /// FOFX_NOSKIPJUNCTIONS = 0x00010000, /// If possible, create a hard link rather than a new instance of the file in the destination. FOFX_PREFERHARDLINK = 0x00020000, /// /// If an operation requires elevated rights and the FOF_NOERRORUI flag is set to disable error UI, display a UAC UI prompt nonetheless. /// FOFX_SHOWELEVATIONPROMPT = 0x00040000, /// /// If FOFX_EARLYFAILURE is set together with FOF_NOERRORUI, the entire set of operations is stopped upon encountering any error /// in any operation. This flag is valid only when FOF_NOERRORUI is set. /// FOFX_EARLYFAILURE = 0x00100000, /// /// Rename collisions in such a way as to preserve file name extensions. This flag is valid only when FOF_RENAMEONCOLLISION is /// also set. /// FOFX_PRESERVEFILEEXTENSIONS = 0x00200000, /// /// Keep the newer file or folder, based on the Date Modified property, if a collision occurs. This is done automatically with no /// prompt UI presented to the user. /// FOFX_KEEPNEWERFILE = 0x00400000, /// Do not use copy hooks. FOFX_NOCOPYHOOKS = 0x00800000, /// Do not allow the progress dialog to be minimized. FOFX_NOMINIMIZEBOX = 0x01000000, /// /// Copy the security attributes of the source item to the destination item when performing a cross-volume move operation. /// Without this flag, the destination item receives the security attributes of its new folder. /// FOFX_MOVEACLSACROSSVOLUMES = 0x02000000, /// Do not display the path of the source item in the progress dialog. FOFX_DONTDISPLAYSOURCEPATH = 0x04000000, /// Do not display the path of the destination item in the progress dialog. FOFX_DONTDISPLAYDESTPATH = 0x08000000, /// /// Introduced in Windows Vista SP1. The user expects a requirement for rights elevation, so do not display a dialog box asking /// for a confirmation of the elevation. /// FOFX_REQUIREELEVATION = 0x10000000, /// /// Introduced in Windows 8. The file operation was user-invoked and should be placed on the undo stack. This flag is preferred /// to FOF_ALLOWUNDO. /// FOFX_ADDUNDORECORD = 0x20000000, /// Introduced in Windows 7. Display a Downloading instead of Copying message in the progress dialog. FOFX_COPYASDOWNLOAD = 0x40000000, /// Introduced in Windows 7. Do not display the location line in the progress dialog. FOFX_DONTDISPLAYLOCATIONS = 0x80000000, } /// /// Exposes methods to copy, move, rename, create, and delete Shell items as well as methods to provide progress and error dialogs. /// This interface replaces the SHFileOperation function. /// [PInvokeData("Shobjidl.h")] [ComImport, Guid("947aab5f-0a5c-4c13-b4d6-4bf7836fc9f8"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown), CoClass(typeof(CFileOperations))] public interface IFileOperation { /// Enables a handler to provide status and error information for all operations. /// Pointer to an IFileOperationProgressSink object to be used for progress status and error notifications. /// /// When this method returns, this parameter points to a returned token that uniquely identifies this connection. The calling /// application uses this token later to delete the connection by passing it to IFileOperation::Unadvise. If the call to Advise /// fails, this value is meaningless. /// uint Advise(IFileOperationProgressSink pfops); /// Terminates an advisory connection previously established through IFileOperation::Advise. /// /// The connection token that identifies the connection to delete. This value was originally retrieved by Advise when the /// connection was made. /// void Unadvise(uint dwCookie); /// Sets parameters for the current operation. /// /// Flags that control the file operation. This member can be a combination of the following flags. FOF flags are defined in /// Shellapi.h and FOFX flags are defined in Shobjidl.h. /// void SetOperationFlags(FILEOP_FLAGS dwOperationFlags); /// This method is not implemented. /// The message. [Obsolete] void SetProgressMessage([MarshalAs(UnmanagedType.LPWStr)] string pszMessage); /// Specifies a dialog box used to display the progress of the operation. /// Pointer to an IOperationsProgressDialog object that represents the dialog box. void SetProgressDialog(IOperationsProgressDialog popd); /// Declares a set of properties and values to be set on an item or items. /// /// Pointer to an IPropertyChangeArray, which accesses a collection of IPropertyChange objects that specify the properties to be /// set and their new values. /// void SetProperties(PropSys.IPropertyChangeArray pproparray); /// Sets the parent or owner window for progress and dialog windows. /// A handle to the owner window of the operation. This window will receive error messages. void SetOwnerWindow(HWND hwndParent); /// Declares a single item whose property values are to be set. /// Pointer to the item to receive the new property values. void ApplyPropertiesToItem(IShellItem psiItem); /// Declares a set of items for which to apply a common set of property values. /// /// Pointer to the IUnknown of the IShellItemArray, IDataObject, or IEnumShellItems object which represents the group of items. /// You can also point to an IPersistIDList object to represent a single item, effectively accomplishing the same function as IFileOperation::ApplyPropertiesToItem. /// void ApplyPropertiesToItems([MarshalAs(UnmanagedType.IUnknown)] object punkItems); /// Declares a single item that is to be given a new display name. /// Pointer to an IShellItem that specifies the source item. /// Pointer to the new display name of the item. This is a null-terminated, Unicode string. /// /// Pointer to an IFileOperationProgressSink object to be used for status and failure notifications. If you call /// IFileOperation::Advise for the overall operation, progress status and error notifications for the rename operation are /// included there, so set this parameter to NULL. /// void RenameItem(IShellItem psiItem, [MarshalAs(UnmanagedType.LPWStr)] string pszNewName, IFileOperationProgressSink pfopsItem); /// Declares a set of items that are to be given a new display name. All items are given the same name. /// /// Pointer to the IUnknown of the IShellItemArray, IDataObject, or IEnumShellItems object which represents the group of items to /// be renamed. You can also point to an IPersistIDList object to represent a single item, effectively accomplishing the same /// function as IFileOperation::RenameItem. /// /// Pointer to the new display name of the items. This is a null-terminated, Unicode string. void RenameItems([MarshalAs(UnmanagedType.IUnknown)] object pUnkItems, [MarshalAs(UnmanagedType.LPWStr)] string pszNewName); /// Declares a single item that is to be moved to a specified destination. /// Pointer to an IShellItem that specifies the source item. /// /// Pointer to an IShellItem that specifies the destination folder to contain the moved item. /// /// /// Pointer to a new name for the item in its new location. This is a null-terminated Unicode string and can be NULL. If NULL, /// the name of the destination item is the same as the source. /// /// /// Pointer to an IFileOperationProgressSink object to be used for progress status and error notifications for this specific move /// operation. If you call IFileOperation::Advise for the overall operation, progress status and error notifications for the move /// operation are included there, so set this parameter to NULL. /// void MoveItem(IShellItem psiItem, IShellItem psiDestinationFolder, [MarshalAs(UnmanagedType.LPWStr)] string pszNewName, IFileOperationProgressSink pfopsItem); /// Declares a set of items that are to be moved to a specified destination. /// /// Pointer to the IUnknown of the IShellItemArray, IDataObject, or IEnumShellItems object which represents the group of items to /// be moved. You can also point to an IPersistIDList object to represent a single item, effectively accomplishing the same /// function as IFileOperation::MoveItem. /// /// /// Pointer to an IShellItem that specifies the destination folder to contain the moved items. /// void MoveItems([MarshalAs(UnmanagedType.IUnknown)] object punkItems, IShellItem psiDestinationFolder); /// Declares a single item that is to be copied to a specified destination. /// Pointer to an IShellItem that specifies the source item. /// /// Pointer to an IShellItem that specifies the destination folder to contain the copy of the item. /// /// /// Pointer to a new name for the item after it has been copied. This is a null-terminated Unicode string and can be NULL. If /// NULL, the name of the destination item is the same as the source. /// /// /// Pointer to an IFileOperationProgressSink object to be used for progress status and error notifications for this specific copy /// operation. If you call IFileOperation::Advise for the overall operation, progress status and error notifications for the copy /// operation are included there, so set this parameter to NULL. /// void CopyItem(IShellItem psiItem, IShellItem psiDestinationFolder, [MarshalAs(UnmanagedType.LPWStr)] string pszCopyName, IFileOperationProgressSink pfopsItem); /// Declares a set of items that are to be copied to a specified destination. /// /// Pointer to the IUnknown of the IShellItemArray, IDataObject, or IEnumShellItems object which represents the group of items to /// be copied. You can also point to an IPersistIDList object to represent a single item, effectively accomplishing the same /// function as IFileOperation::CopyItem. /// /// /// Pointer to an IShellItem that specifies the destination folder to contain the copy of the items. /// void CopyItems([MarshalAs(UnmanagedType.Interface)] object punkItems, IShellItem psiDestinationFolder); /// Declares a single item that is to be deleted. /// Pointer to an IShellItem that specifies the item to be deleted. /// /// Pointer to an IFileOperationProgressSink object to be used for progress status and error notifications for this specific /// delete operation. If you call IFileOperation::Advise for the overall operation, progress status and error notifications for /// the delete operation are included there, so set this parameter to NULL. /// void DeleteItem(IShellItem psiItem, IFileOperationProgressSink pfopsItem); /// Declares a set of items that are to be deleted. /// /// Pointer to the IUnknown of the IShellItemArray, IDataObject, or IEnumShellItems object which represents the group of items to /// be deleted. You can also point to an IPersistIDList object to represent a single item, effectively accomplishing the same /// function as IFileOperation::DeleteItem. /// void DeleteItems([MarshalAs(UnmanagedType.IUnknown)] object punkItems); /// Declares a new item that is to be created in a specified location. /// /// Pointer to an IShellItem that specifies the destination folder that will contain the new item. /// /// /// A bitwise value that specifies the file system attributes for the file or folder. See GetFileAttributes for possible values. /// /// /// Pointer to the file name of the new item, for instance Newfile.txt. This is a null-terminated, Unicode string. /// /// /// Pointer to the name of the template file (for example Excel9.xls) that the new item is based on, stored in one of the /// following locations: /// /// /// CSIDL_COMMON_TEMPLATES. The default path for this folder is %ALLUSERSPROFILE%\Templates. /// /// /// CSIDL_TEMPLATES. The default path for this folder is %USERPROFILE%\Templates. /// /// /// %SystemRoot%\shellnew /// /// /// /// This is a null-terminated, Unicode string used to specify an existing file of the same type as the new file, containing the /// minimal content that an application wants to include in any new file. /// /// This parameter is normally NULL to specify a new, blank file. /// /// /// Pointer to an IFileOperationProgressSink object to be used for status and failure notifications. If you call /// IFileOperation::Advise for the overall operation, progress status and error notifications for the creation operation are /// included there, so set this parameter to NULL. /// void NewItem(IShellItem psiDestinationFolder, FileAttributes dwFileAttributes, [MarshalAs(UnmanagedType.LPWStr)] string pszName, [MarshalAs(UnmanagedType.LPWStr)] string pszTemplateName, IFileOperationProgressSink pfopsItem); /// Executes all selected operations. /// /// This method is called last to execute those actions that have been specified earlier by calling their individual methods. For /// instance, RenameItem does not rename the item, it simply sets the parameters. The actual renaming is done when you call PerformOperations. /// void PerformOperations(); /// /// Gets a value that states whether any file operations initiated by a call to IFileOperation::PerformOperations were stopped /// before they were complete. The operations could be stopped either by user action or silently by the system. /// /// /// When this method returns, points to TRUE if any file operations were aborted before they were complete; otherwise, FALSE. /// [return: MarshalAs(UnmanagedType.Bool)] bool GetAnyOperationsAborted(); } /// CLSID_FileOperations [ComImport, Guid("3ad05575-8857-4850-9277-11b85bdb8e09"), ClassInterface(ClassInterfaceType.None)] public class CFileOperations { } } }