SHFileOperation function
Performs file operations such as copy, move, rename, and delete.
Syntax
BOOL SHFileOperation(
_Inout_ LPSHFILEOPSTRUCT lpFileOp
);
Parameters
| Parameter | Description |
|---|---|
lpFileOp |
A pointer to a SHFILEOPSTRUCT structure that contains the details of the file operation to be performed.
|
Return value
Returns a nonzero value if the operation is successful, or zero otherwise.
Important:
This function is not recommended for use. Applications that need to perform file operations should use the Microsoft® .NET Framework file I/O classes, such as System.IO.File and System.IO.Directory, or the IFileOperation interface.
Remarks
The SHFileOperation function performs a variety of file operations, including:
- Copying files
- Moving files
- Renaming files
- Deleting files
- Creating directories
- Displaying a progress dialog
The operation to be performed is specified by the wFunc member of the SHFILEOPSTRUCT structure.
Flags
The fFlags member of the SHFILEOPSTRUCT structure can be set to one or more of the following flags:
| Flag | Description |
|---|---|
FOF_ALLOWUNDO |
Enables undo functionality for the operation. |
FOF_CONFIRMATIONSONLY |
Prompts the user for confirmation before performing any operation that requires it. |
FOF_FILESONLY |
Performs the operation only on files. |
FOF_NOCONFIRMMKDIR |
Do not prompt the user for confirmation when creating a directory. |
FOF_NOCONFIRMSHADOW |
Do not prompt the user for confirmation if the destination file is a read-only file. |
FOF_NOERRORUI |
Do not display any error message boxes. |
FOF_NORECURSEREPARSE |
Do not follow reparse points. |
FOF_RENAMEONCOLLISION |
If a file with the same name already exists in the destination, rename the file being copied or moved. |
FOF_SILENT |
Do not display any dialog boxes, such as progress or confirmation dialogs. |
FOF_SIMPLEPROGRESSTEXT |
Displays a simpler progress dialog. |
FOF_STATUSTEXT |
Displays the status text in the progress dialog. |
SHFILEOPSTRUCT Structure
SHFILEOPSTRUCT
typedef struct _SHFILEOPSTRUCT {
HWND hwnd;
UINT wFunc;
_In_NLS_CHOST_INSECURE_ LPCTSTR pszFrom;
_In_NLS_CHOST_INSECURE_ LPCTSTR pszTo;
FILEOP_FLAGS fFlags;
BOOL fAnyOperationsAborted;
_Inout_opt_ LPVOID hNameMappings;
_In_NLS_CHOST_INSECURE_ LPCTSTR pszRoot;
} SHFILEOPSTRUCT, *LPSHFILEOPSTRUCT;
hwnd: Handle to the owner window that will host any dialog boxes displayed by this function.wFunc: The file operation to perform (e.g.,FO_COPY,FO_MOVE,FO_DELETE,FO_RENAME).pszFrom: Pointer to a null-terminated string that specifies the source file(s) or directory. Multiple files are separated by '\0'.pszTo: Pointer to a null-terminated string that specifies the destination file or directory.fFlags: Flags that control the behavior of the function.fAnyOperationsAborted: Receives a value that indicates whether any operations were aborted by the user.hNameMappings: Used internally. Should beNULL.pszRoot: Pointer to a null-terminated string that specifies the root of the directory tree. Used to qualify thepszFromandpszTopaths.