?
Solved

Copy/Move folder

Posted on 2003-03-07
2
Medium Priority
?
289 Views
Last Modified: 2008-02-01
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
Comment
Question by:BWarmuskerken
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 5

Accepted Solution

by:
Kocil earned 600 total points
ID: 8093024
#include <shellapi.h>
0
 

Expert Comment

by:BungoMan
ID: 8093086
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question