Microsoft Docs

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

MemberTypeDescription
hwndHWNDHandle to the window that owns the dialog box for progress, error, and confirm messages.
wFuncUINTSpecifies the operation to be performed. Can be one of FO_COPY, FO_DELETE, FO_MOVE, or FO_RENAME.
pFromPCZZTSTRPointer to a double‑null‑terminated string that contains the source file name(s).
pToPCZZTSTRPointer to a double‑null‑terminated string that contains the destination file name(s). Used only for copy or move.
fFlagsFILEOP_FLAGSFlags that control the operation’s behavior (e.g., FOF_ALLOWUNDO, FOF_NOCONFIRMATION).
fAnyOperationsAbortedBOOLSet to TRUE if the user aborts the operation.
hNameMappingsLPVOIDHandle to a name‑mapping array returned when FOF_WANTMAPPINGHANDLE is set.
lpszProgressTitlePCTSTRTitle of the progress dialog box. If NULL, a default title is used.

Remarks

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;
}

See Also