请教拷贝文件夹中涉及到的字符串格式问题!在线等……
编写了一个应用程序,功能是将应用程序所在的当前目录中的“source”文件夹拷贝到指定的目录下,具体的函数调用关系如下:
{
char sourcePath[MAX_PATH];
CString destPath;
pDialog3->m_FileListCtl.GetWindowText(destPath);
//pDialog3->m_FileListCtl是一个无模式对话框的组合框控件
GetCurrentDirectory(MAX_PATH,sourcePath); //获得当前目录
strcat(sourcePath,"\\source"); //指到source文件夹
CString sourPath;
sourPath.Format(_T("%s"),sourcePath); //字符格式转换
::CopyDirectory(m_hWnd,sourPath,destPath); //拷贝文件夹操作函数
}
此时,我在这儿设置断点后,发现sourPath的路径是:“f:\source”,与我的要求相吻合,但是拷贝时提示“拷贝文件错误”,而我将之改成
::CopyDirectory(m_hWnd,“f:\\source”,destPath)时,文件就能够拷贝了,到底是怎么回事呢?
CopyDirectory函数如下:
int CopyDirectory(HWND Handle,LPCTSTR PathOut,LPCTSTR PathIn)
{
SHFILEOPSTRUCT op;
ZeroMemory(&op, sizeof(op));
op.hwnd = Handle; //HWND_DESKTOP;
op.wFunc = FO_COPY;
op.pFrom = PathOut;
op.pTo = PathIn;
op.fFlags = FOF_SIMPLEPROGRESS|FOF_FILESONLY
|FOF_RENAMEONCOLLISION|FOF_WANTMAPPINGHANDLE;
int Re = SHFileOperation(&op);
return Re;
}