• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 302
  • Last Modified:

Copy/Move folder

I'm fairly new to C++, converting from VB.  In VB I've used the Shell Object to move, copy and delete folders.  I've done some searching on the site, and have come across this sample code listed below.  Being a newbie, I cannot get my app to compile, I get the following error:  'SHFILEOPSTRUCT' : undeclared identifier

I must be missing a header or lib.  Anyone?

int CopyFolder(LPCTSTR lpExistingFolderName, LPCTSTR lpNewFolderName)
{
     SHFILEOPSTRUCT sfo;

     ZeroMemory ( &sfo, sizeof ( SHFILEOPSTRUCT));

     sfo.pFrom = lpExistingFolderName;
     sfo.pTo = lpNewFolderName;
     sfo.fFlags = FOF_FILESONLY | FOF_NOCONFIRMATION | FOF_SILENT;

     int i = SHFileOperation ( &sfo);
        return i;
}
0
BWarmuskerken
Asked:
BWarmuskerken
1 Solution
 
KocilCommented:
#include <shellapi.h>
0
 
BungoManCommented:
i know this wasnt my question, but this is something i was wondering about myself, i tried that code and it compiled and linked with no warnings or errors, but it doesnt seem to do anything

#include "stdafx.h"
#include <windows.h>
#include <shellapi.h>
#include <iostream>

int CopyFolder(LPCTSTR lpExistingFolderName, LPCTSTR lpNewFolderName);

using namespace std;

void main()
{
     cout << "Copying Folder." << endl;
     
     CopyFolder("School","Bah");
}

int CopyFolder(LPCTSTR lpExistingFolderName, LPCTSTR lpNewFolderName)
{
    SHFILEOPSTRUCT sfo;

    ZeroMemory (&sfo,sizeof(SHFILEOPSTRUCT));

    sfo.pFrom=lpExistingFolderName;
    sfo.pTo=lpNewFolderName;
    sfo.fFlags=FOF_FILESONLY|FOF_NOCONFIRMATION|FOF_SILENT;

     int i=SHFileOperation(&sfo);

     return i;
}

"School" is an existing folder in the directory that the program is run in, and Bah is a folder that does not exist.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now