SHFILEOPSTRUCT Structure
The SHFILEOPSTRUCT
structure contains information that the SHFileOperation
function uses to perform file operations such as copy, move, delete, or rename.
Syntax
#include <windows.h>
#include <shlobj.h>
typedef struct _SHFILEOPSTRUCT {
HWND hwnd;
UINT wFunc;
PCZZTSTR pFrom;
PCZZTSTR pTo;
FILEOP_FLAGS fFlags;
BOOL fAnyOperationsAborted;
LPVOID hNameMappings;
PCTSTR lpszProgressTitle;
} SHFILEOPSTRUCT, *LPSHFILEOPSTRUCT;
Members
Member | Type | Description |
---|---|---|
hwnd | HWND | Handle to the window that owns the dialog box for progress, error, and confirm messages. |
wFunc | UINT | Specifies the operation to be performed. Can be one of FO_COPY , FO_DELETE , FO_MOVE , or FO_RENAME . |
pFrom | PCZZTSTR | Pointer to a double‑null‑terminated string that contains the source file name(s). |
pTo | PCZZTSTR | Pointer to a double‑null‑terminated string that contains the destination file name(s). Used only for copy or move. |
fFlags | FILEOP_FLAGS | Flags that control the operation’s behavior (e.g., FOF_ALLOWUNDO , FOF_NOCONFIRMATION ). |
fAnyOperationsAborted | BOOL | Set to TRUE if the user aborts the operation. |
hNameMappings | LPVOID | Handle to a name‑mapping array returned when FOF_WANTMAPPINGHANDLE is set. |
lpszProgressTitle | PCTSTR | Title of the progress dialog box. If NULL , a default title is used. |
Remarks
- Both
pFrom
andpTo
must be double‑null‑terminated. For multiple files, separate each file name with a single null character. - When moving files across different volumes, the operation becomes a copy‑and‑delete.
- Setting
FOF_SILENT
suppresses the progress dialog, but error messages may still appear.
Example
#include <windows.h>
#include <shlobj.h>
#include <stdio.h>
int main(void) {
SHFILEOPSTRUCT op = {0};
op.wFunc = FO_COPY;
op.pFrom = "C:\\Source\\file.txt\\0C:\\Source\\image.png\\0\\0"; // double‑null terminated
op.pTo = "D:\\Dest\\\\0\\0";
op.fFlags = FOF_NOCONFIRMATION | FOF_SILENT;
int ret = SHFileOperation(&op);
if (ret == 0 && !op.fAnyOperationsAborted) {
printf("Copy succeeded.\n");
} else {
printf("Copy failed or aborted.\n");
}
return 0;
}