cFileOperation 0.1
Display the latest version of the copy/move/delete progress dialog and the related prompts.
SHFileOperation has been superseded by IFileOperation on Windows Vista and above. At least the basic parts of it are easy to access in VB6- showing the standard Windows dialog/progress boxes to Move, Copy, or Delete files. While the class handles it, this function also requires us to bring in the IShellItem interface and its relatives into VB, so take a look at the class module code if you ever wanted to use other functions that required this.
PROJECT UPDATE 30 Apr 2016:
Cancelling through code
I'm updating the project to show how to cancel operations through code. While there doesn't seem to be built-in way to cancel e.g. in the middle of a large file, you can cancel between items by using the VTable-swap technique to replace the subs in the callback class with functions that can return an error in the HRESULT (I use E_ABORT). This technique has been implemented for Multiple Files copy in the demo project. Also note that the project now references the latest version of oleexp.tlb, while the previous version still used a 3.x version, so if you haven't downloaded that yet you'll either need to, or (not recommended but possible) change the references back..
Project Update - 17 Apr 2015
The project now includes a template class implementing the IFileOperationProgressSink, so you can get feedback while the dialog is running. Examples of what to do with that information are included, like getting the final name, or passing progress back to the application.
Note:
If there's an error in a function called from the events class, the operation will not be performed but the result will say that it was. So if everything else looks right but an operation isn't happening, check that. Took me a while to catch such a problem.
-----
From MSDN, advantages to IFileOperation:
RequirementsUse of IShellItem to identify items rather than string paths. SHFileOperation required path and destination strings to terminate in two null characters rather than the standard single null character, which itself was used to delimit multiple paths in the string. Identifying an item through IShellItem is more robust and less prone to programming errors. It also allows you to access non-file system items such as virtual folders. Multiple items in one operation can be passed as an IShellItemArray, IDataObject, or a collection accessed through IEnumShellItems rather than as a string.
More accurate error reporting through HRESULT values in conjunction with an API such as FormatMessage. Return codes from SHFileOperation could be misleading or inaccurate.
Extensibility. As a Component Object Model (COM) interface, IFileOperation can have its capabilities extended by a third-party to meet their specific needs, although this should be a very rare case. Windows provides a default implementation of IFileOperation that should meet the needs of most users.
Better progress feedback. Detailed operation progress, including notifications when specific operations begin and end on individual items as well as the overall progress, can be received during the operation. While SHFileOperation did provide progress UI, it was not as detailed.
More functionality. In addition to the copy, delete, move, and rename functionality provided by SHFileOperation, IFileOperation allows you to apply property values and create new items.
More control over the operation. In addition to the operation flags recognized by SHFileOperation, new flags are recognized in IFileOperation::SetOperationFlags that specify extended operation options.
Different operations can be performed in one call. For instance, you can move a set of files, copy others, rename a folder, and apply properties to yet another item all in one operation. SHFileOperation could only do one operation—copy, move, rename, or delete—at a time.
-IFileOperation is only available on Windows Vista and higher; this project will not work on XP.
-Requires oleexp.tlb v4.0 or higher
Usage Summary
Using the class is fairly straight forward;
-Make sure the project's reference to oleexp.tlb is correct
-Add the class module to the project and go nuts.
-Sample project included to show how the class is called.
The Class
Once you've added oleexp, you're ready to start using cFileOperation. Since this calls the native methods, everything functions the same as in Explorer, including prompts about overwriting, confirmation deletion, etc. No extra code is needed to handle that.
Here are the currently supported calls:
.ParentWindow - Specify the parent window (e.g. Form1.hWnd) to keep the dialogs on top of it.
.SingleFile - For performing operations on a single file.
.SetFileList - For multiple files, specify an array containing a single full path to a file in each item.
.FileList - Retrieve the current file list.
.DestFolder - The destination folder; don't need to set for Delete.
.Flags - Set flags for the operation; uses the standard FileOperationFlags enum (see below).
.CopyFile - Copies the single file.
.CopyFiles - Copies the file list.
.MoveFile - Moves the single file.
.MoveFiles - Moves the file list.
.DeleteFile - Deletes the single file.
.DeleteFiles - Deletes the file list.
File Operation Flags
See MSDN Description of Flags
Can't put it much better than MSDN.
-------
All bug reports, comments, criticisms, and suggestions welcome.
PLEASE NOTE: I don't have access to multiple test systems; everything works on Win7 x64, and everything should work from Vista through 10, but please let met know if there's an issue.
--------------------------
Project update 24 Nov 2016: Updated to reference oleexp v4.0 or higher
twinBASIC 64bit compatible version at https://github.com/fafalone/MiscDemos





Reply With Quote