Virtual Developer Workshop: Containerized Development with Docker

This is the CShellFileOp class. I wrote this so i could use the standard windows explorer copy/move/delete/rename file methods. The idea is to create a CShellFileOp object, add all the source path/filenames and destination path/filenames and then delete/copy/move/rename.

A sample function has been included which shows a multiple file copy operation.

// ShellFileOp.h: interface for the CShellFileOp class.
//	Tim Johnson		timj@progsoc.uts.edu.au
//	Written : July 1998
//	Copyright 1998

#if !defined(AFX_SHELLFILEOP_H__DA3A3661_1EF3_11D2_9E56_444553540000__INCLUDED_)
#define AFX_SHELLFILEOP_H__DA3A3661_1EF3_11D2_9E56_444553540000__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

//constats for use in iSrcDest arguements
#define SH_SRC_FILE  0
#define SH_DEST_FILE 1

class CShellFileOp  

	//simple constructor
	//complex constructor - performs the operation straight away
	CShellFileOp( const HWND phWnd, 
				  const UINT wFunc,
				  const CString sFrom,
				  const CString sTo,
				  const FILEOP_FLAGS fFlags,
				  const CString sProgressTitle);

	virtual ~CShellFileOp();

public: //operations

	// Function to perform copy operation
	long CopyFiles();
	// Function to perform delete operation
	long DeleteFiles();
	// Function to perform move operation
	long MoveFiles();
	// Function to perform rename operation
	long RenameFiles();
	// Adds another filename to the end of the current string
	void AddFile(const int iSrcDest, const CString sFile);
	// Clears a list of files
	void ClearFiles(const int iSrcDest);
	// Function to pre-allocate string memory to prevent 
	//  lots of re-allocations
	void SetMaxCount(const int iSrcDest, const long lMax);
	// Function to set the dialog title
	//  sTitle is a string to be used
	//  nTitle is a resource ID to get the string from
	void SetTitle(CString sTitle);
	void SetTitle(const int nTitle);
	// Function to set the parent HWND of the dialog
	void SetParent(const HWND phWnd);
	// Function to get Abort flag
	BOOL AnyOperationsAborted() const;
	// Functions to get/set the operation flags
	//	Flags that control the file operation. This member can be a combination of the 
	//	following values: 
	//	FOF_ALLOWUNDO			Preserves undo information, if possible. 
	//	FOF_CONFIRMMOUSE		Not implemented. 
	//	FOF_FILESONLY			Performs the operation only on files if a wildcard 
	//							filename (*.*) is specified. 
	//	FOF_MULTIDESTFILES		Indicates that the pTo member specifies multiple destination 
	//							files (one for each source file) rather than one directory 
	//							where all source files are to be deposited. 
	//	FOF_NOCONFIRMATION		Responds with "yes to all" for any dialog box that is 
	//							displayed. 
	//	FOF_NOCONFIRMMKDIR		Does not confirm the creation of a new directory if the 
	//							operation requires one to be created. 
	//	FOF_RENAMEONCOLLISION	Gives the file being operated on a new name (such as 
	//							"Copy #1 of...") in a move, copy, or rename operation if a 
	//							file of the target name already exists. 
	//	FOF_SILENT				Does not display a progress dialog box. 
	//	FOF_SIMPLEPROGRESS		Displays a progress dialog box, but does not show the 
	//							filenames. 
	FILEOP_FLAGS GetFlags() const;
	void SetFlags(const FILEOP_FLAGS fNewFlags);

private:	//operations
	// function to grab some string space memory
	void GrabMem(const int iSrcDest, const long lNum);

private:	//attributes
	//max no. char in source string
	long m_lMaxSrcCount;
	//max no. char in dest string
	long m_lMaxDestCount;
	//current no. char in source string
	long m_lCurSrcCount;
	//current no. char in dest string
	long m_lCurDestCount;
	//structure for shell call
	//pointer to start of source string
	char * m_pTo;
	//pointer to start of dest string
	char * m_pFrom;
	//current pointer in source string
	char * m_pSrc;
	//current pointer in dest string
	char * m_pDest;	
	//title to be used on dialog
	char * m_pTitle;

#endif // !defined(AFX_SHELLFILEOP_H__DA3A3661_1EF3_11D2_9E56_444553540000__INCLUDED_)

Download source - 5 KB

Last updated: November 21, 1998


  • Licnese?

    Posted by Cornelia on 03/06/2015 07:52am

    Nice article. Could you provide the license information.

  • How to self-delete?

    Posted by Legacy on 06/01/2000 07:00am

    Originally posted by: Nick

    Does anybody have knowledge about:
    How to self-delete the (exe) file of a running app?
    Trying to write an uninstaller which would be nice to delete itself at the end, but it doesn't.
    Any help is appreciated.

  • project creation of the expamle

    Posted by Legacy on 05/10/2000 07:00am

    Originally posted by: d-man

    I'm interested in the class but lack the knowledge of how to create a project and implement this in a WIN NT / W9x box environment. Anf info would be GREATLY appreciated.

    thanks ...

  • how to handle the end of fucntion?

    Posted by Legacy on 01/03/2000 08:00am

    Originally posted by: lgf

    when you call the SHFileOperation() function ,
    How to handle the end of function?

  • SHFileOperation Error Codes

    Posted by Legacy on 12/15/1999 08:00am

    Originally posted by: Erich Hermann

    An operation failed if the function returns non-zero.

    Where can I find constants for and meanings of the numbers?

    Is there a text-conversion function like FormatMessage to convert the number into a string for output/logging?


    • Meaning of SHFileOperation error codes

      Posted by iatethewholething on 09/21/2006 11:12am

      Check out: http://shellrevealed.com/blogs/shellblog/archive/2006/09/11/Common-Questions-Concerning-the-SHFileOperation-API_3A00_-Part-1.aspx Explains why the error codes returned from SHFileOperation are funky.

  • Sending to Recycle Bin

    Posted by Legacy on 04/26/1999 07:00am

    Originally posted by: Michael Simons

    Your comments in the source code should have said that FOF_ALLOWUNDO with a DeleteFiles operation will send the file to the recycle bin. The most useful Shell File Operation.

  • SHFileOperation wrapper

    Posted by Legacy on 03/31/1999 08:00am

    Originally posted by: Nir Ofer

    As long as you have gone to all that trouble to wrap the
    SHFileOperation why not make it add the NULL seperators by
    itself (whoever is using the class shouldn't mess around
    with NULLs). I did this, and it looks cleaner.

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date