Link to home
Start Free TrialLog in
Avatar of rpatna
rpatna

asked on

copy a directory

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.
ASKER CERTIFIED SOLUTION
Avatar of Roshan Davis
Roshan Davis
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rpatna
rpatna

ASKER

Thanks , it is working fine.

now tell me how to remove full directory?
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
Avatar of rpatna

ASKER

Thanks roshmon, it is working fine.

Welcome :o)
Avatar of rpatna

ASKER

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 ?





     

use sprintf
Avatar of rpatna

ASKER

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????
Cast like this

(LPCTSTR)(LPTSTR)csSTRING
Avatar of rpatna

ASKER


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

type cast also not working.


Show me how u declared pszTo, and pszFrom

Rosh :)