Move Copy
Delete Recycle
Site Map Feedback

Download:

Up DTree Local Picker Recycle ResFile Temp

In C++ there seem to be many ways to open files, copy them, delete them... Sometimes certain ways don't work and you end up wondering why - then it turns out to be a problem with long file names or something else ridiculous. But Windows itself uses a nice little dialog that gives a (random?) "time left estimate" and a progress bar. Its can delete Directory Trees, Read only folders and files, and delete to the recycle bin.... So shouldn't we all be using this?

Here's a little class that wraps the Windows Shell magic.

To delete a File or Folder (which doesn't need to be empty):
  CRecycle::Delete("Test");
If you had a list of Directory Trees to delete, use a string of strings (double null terminator):
  CRecycle::Delete(CString("Test")+'\0'+"Test2"+'\0');
If you give the full path, CRecycle will delete to the Recycle Bin - unless you say:
  CRecycle::Delete("Test\0Test2\0",false);
The following code gets the full path for a file:
  CString Path;
  DWORD Length=GetFullPathName(Path,0,0,0); // Make relative paths absolute:
  GetFullPathName(Path, Length, Path.GetBufferSetLength(Length), 0);
  Path.ReleaseBuffer();

it will also Move and Copy lists of files giving the standard Windows Move/Copy Progress Bar Dialog. Since this implementation is meant for an Application to use, there is no user feedback with regard to Read-Only files etc. Everything that can be Moved, Deleted or Copied will be.

FlushDrive is used to ensure the operation was completed on removable media and let Windows know that the media can now be removed.


THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.