-1

What is the difference between the two functions?

user8056359
  • 437
  • 1
  • 7
  • 16
  • 1
    The shell often seemingly duplicates functionality. Beyond the ability to batch, get progress feedback and delete to the recycle bin, the bigger difference is that the item does not have to be a file. Googling "shell namespace extensions" might help. – Hans Passant Oct 16 '17 at 11:21

3 Answers3

1
  • DeleteFile is a low-level function that only deletes files on file systems and file shares supported by Windows.

  • IFileOperation::DeleteItem deletes items in the shell namespace.

DeleteItem can in theory be used to delete control panel items, ftp files/folders and anything else that lives in the shell namespace and has the SFGAO_CANDELETE set. If the IShellItem passed to DeleteItem is a file on a normal file system then DeleteFile will ultimately be used to delete the file.

The shell namespace model has existed since Windows 95 (IShellFolder and friends) but IFileOperation only exists in Vista and later and is part of the new shell copy engine added to those systems.

Anders
  • 97,548
  • 12
  • 110
  • 164
  • `IFileOperation` will recursively delete a filesystem directory, which in the Windows API would require walking the tree via `FindFirstFile`, `FindNextFile` and deleting files with `DeleteFile` and directories with `RemoveDirectory` (carefully retrying if anti-malware scanners add asynchronous delays by keeping their own handles open to scan files). `IFileOperation` also defaults to using the recycle bin (if possible based on path length), Explorer's undo operation, and error dialogs including requesting UAC elevation when necessary. – Eryk Sun Oct 16 '17 at 20:55
0

DeleteFile is an older component of the WinAPI, and is generally more supported across older systems.

IFileOperation::DeleteItem is a newer method (possibly calling DeleteFile downstream) used to integrate with a different API ecosystem than the standard WinAPI.

The IFileOperation base has greater flexibility and object-oriented design than DeleteFile (which is more of an "atomic" operation). In terms of deleting a file, they are essentially behaviorally the same.

Scott Mudge
  • 957
  • 6
  • 18
  • The is also [SHFileOperation](https://msdn.microsoft.com/en-us/library/windows/desktop/bb762164(v=vs.85).aspx) to be mentioned... – xMRi Oct 16 '17 at 11:47
0

IFileOperation::DeleteItem Allows you to give feedback and progress on the operation. While DeleteFile gives no feedback, just the result of the operation.

Eyal Cinamon
  • 939
  • 5
  • 16
  • `IFileOperation::DeleteItem` can not give more feedback(compare with `DeleteFile`) when called for single file. and no any progress here possible - because delete file is synchronous api. – RbMm Oct 16 '17 at 12:15