Http://hi.baidu.com/magicfuzzx/item/cda3c631afc5cb009dc65e0e
In general, we can easily use the delatefile function to delete files. However, another drawback is that the deleted files are not deleted by the recycle bin. If they are deleted by mistake, it will be troublesome, not all users recover data. Microsoft also provides shellapi for us, where the functions can be used for some special operations.
Here we useShfileoperationThe function is defined as follows:
Int shfileoperation (
_ In lpshfileopstruct lpfileop
);
However, Microsoft recommends using Vista and later platforms.IfileoperationInterface to replace this function.
This parameter is a shfileopstruct struct, which is defined as follows:
Typedef struct _ shfileopstruct {
Hwnd; // a dialog box handle used to display the file operation status
Uint wfunc; // the action to be executed
Lpctstr pfrom; // source file path
Lpctstr PTO; // target file path
Fileop_flags fflags; // understand the additional operation options, which can be used | Operator
Bool fanyoperationsaborted; // determines whether it can be interrupted.
Lpvoid hnamemappings; // you can create a file ing.
Lpctstr lpszprogresstitle; // specify the window name when it is marked as fof_simpleprogress
} Shfileopstruct, * lpshfileopstruct;
Reference connection: http://msdn.microsoft.com/en-us/library/bb759795%28v=vs.85%29.aspx
The code for moving files directly to the recycle bin without confirmation is as follows:
Bool delfiletorecycle (lpctstr lpsourcefile)
{
Shfileopstruct shfile;
Zeromemory (& shfile, sizeof (shfile ));
Shfile. pfrom = lpsourcefile;
Shfile. wfunc = fo_delete;
// Silent, retain undo (Recycle Bin), cancel warning
Shfile. fflags = fof_silent | fof_allowundo | fof_noconfirmation;
If (shfileoperation (& shfile )! = 0)
{
Return false;
}
Else
{
Return true;
}
}
Function call is simple: delfiletorecycle (_ T ("D: \ new release document .txt "));