user1485528
user1485528

Reputation:

I can't delete file using SHFileOperation

I want to delete a file into recycle bin. I using this code.

    SHFILEOPSTRUCT FileOp;
    FileOp.hwnd = NULL;
    FileOp.wFunc=FO_DELETE; 
    FileOp.pFrom= lpFileName; //it's my value  \\?\C:\WorkFolder\qweqw.docx
    FileOp.pTo = NULL;
    FileOp.fFlags=FOF_ALLOWUNDO|FOF_NOCONFIRMATION;
    FileOp.hNameMappings=NULL;      
    int t_res = SHFileOperation(&FileOp); // t_res = 124
    return t_res;

What's i doing wrong? Thanks in advance.

Upvotes: 2

Views: 3999

Answers (2)

unwind
unwind

Reputation: 400129

The error code is, according to the documentation:

DE_INVALIDFILES 0x7C The path in the source or destination or both was invalid.

You don't mention any analysis of this, so my suggestion would be to dig into how the filename is represented. Is it the proper encoding?

Upvotes: 0

Roman Ryltsov
Roman Ryltsov

Reputation: 69734

  1. What is t_res, it should give the error code and suggest the reason
  2. Note that pFrom takes files, not single file, so you should terminate the buffer with two zeros, see doc excerpt from MSDN:

Although this member is declared as a single null-terminated string, it is actually a buffer that can hold multiple null-delimited file names. Each file name is terminated by a single NULL character. The last file name is terminated with a double NULL character ("\0\0") to indicate the end of the buffer.

Upvotes: 1

Related Questions