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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
DWORD DelTree(LPCSTR pszBase)
{
SHFILEOPSTRUCT sFileOp;
ZeroMemory(&sFileOp, sizeof(SHFILEOPSTRUCT));
sFileOp.wFunc = FO_DELETE;
sFileOp.pFrom = pszBase;
sFileOp.fFlags = FOF_SILENT|FOF_NOCONFIRMAT ION|FOF_NO ERRORUI;
if ( SHFileOperation(&sFileOp) )
{
return GetLastError();
}
return 0;
}
Good Luck
{
SHFILEOPSTRUCT sFileOp;
ZeroMemory(&sFileOp, sizeof(SHFILEOPSTRUCT));
sFileOp.wFunc = FO_DELETE;
sFileOp.pFrom = pszBase;
sFileOp.fFlags = FOF_SILENT|FOF_NOCONFIRMAT
if ( SHFileOperation(&sFileOp) )
{
return GetLastError();
}
return 0;
}
Good Luck
ASKER
Thanks roshmon, it is working fine.
Welcome :o)
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 ?
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
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????
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
(LPCTSTR)(LPTSTR)csSTRING
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 :)
Rosh :)
ASKER
now tell me how to remove full directory?