Solved

copy a directory

Posted on 2003-10-23
11
261 Views
Last Modified: 2013-11-20
I want to copy a whole directory(folder) with all its files to another path or directory or CD.  Need complete code. I'm using MFC in WinNT.
0
Comment
Question by:rpatna
[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
  • 6
  • 5
11 Comments
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 50 total points
ID: 9604865

DWORD Copy_File(LPCSTR pszFrom, LPCSTR pszTo)
{
      SHFILEOPSTRUCT sFileOp;
      ZeroMemory(&sFileOp, sizeof(SHFILEOPSTRUCT));

      sFileOp.wFunc = FO_COPY;
      sFileOp.pFrom = pszFrom;
      sFileOp.pTo = pszTo;
      sFileOp.fFlags = FOF_SILENT|FOF_NOCONFIRMATION|FOF_NOERRORUI;

      if ( SHFileOperation(&sFileOp) )
      {
            return GetLastError();
      }

      return 0;
}
0
 

Author Comment

by:rpatna
ID: 9605336
Thanks , it is working fine.

now tell me how to remove full directory?
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9605398
DWORD DelTree(LPCSTR pszBase)
{
      SHFILEOPSTRUCT sFileOp;
      ZeroMemory(&sFileOp, sizeof(SHFILEOPSTRUCT));

      sFileOp.wFunc = FO_DELETE;
      sFileOp.pFrom = pszBase;
      sFileOp.fFlags = FOF_SILENT|FOF_NOCONFIRMATION|FOF_NOERRORUI;

      if ( SHFileOperation(&sFileOp) )
      {
            return GetLastError();
      }

      return 0;
}

Good Luck
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rpatna
ID: 9605595
Thanks roshmon, it is working fine.

0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9605609
Welcome :o)
0
 

Author Comment

by:rpatna
ID: 9632933
Hi roshmon,

now I'm getting one more problem.

let I'm writing the following code to copy folder

pszFrom = "e:\\Decom\\folder1";
pszTo     = "f:\\Decom";

this code working fine but if I write like :
CString tmpString1,tmpString2;

tmpString1 = "e:\\Decom\\folder1";
tmpString2 = "f:\\Decom";
...
...
pszFrom = tmpString1;
pszTo     = tmpString1;

means if I store pszFrom = some CString variable
or I tried strcpy(pszFrom,charString);
then it is not working

what to do ?





     

0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9632994
use sprintf
0
 

Author Comment

by:rpatna
ID: 9633481
sprintf  showing error:
can not convert parameter1 from "const char *" to "char *"

while debugging in following code, pszFrom showing "e:\\Decom\\folder1"
 but not copying

tmpString1 = "e:\\Decom\\folder1";
...
...
pszFrom = tmpString1;

what to do????
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9633538
Cast like this

(LPCTSTR)(LPTSTR)csSTRING
0
 

Author Comment

by:rpatna
ID: 9633957

in pszTo     = anything like CString or str or "path"
is working
but
pszFrom  = anything except "direct path"  not working.

type cast also not working.


0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9639188
Show me how u declared pszTo, and pszFrom

Rosh :)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to you can convert your project to a Maven project and the Maven plugin should download the source 1 50
fizzArray  challenge 1 108
has77  challenge 9 97
mapAB Challlenge 35 171
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

740 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