Delete a file to the recycle bin from C++

Today, I was looking for a way to delete a file to the recycle bin using C++, but couldn’t find any simple example, so here it is:

SHFILEOPSTRUCT operation;
operation.wFunc = FO_DELETE;
operation.pFrom = "c:\\file\to\delete.txt";
operation.fFlags = FOF_ALLOWUNDO;

SHFileOperation(&operation);

Tags: , ,

One Response to “Delete a file to the recycle bin from C++”

  1. Vesko Says:

    1) operation.pFrom must be end with double zero
    2) operation.fFlags = FOF_ALLOWUNDO|FOF_NO_UI|FOF_NORECURSION;

Copyright © Pogopixels Ltd, 2008-2018