Solved

copy a directory

Posted on 2003-10-23
11
263 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

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!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

690 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