Solved

copy a directory

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

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now