#include "Shellapi.h"
#include "tchar.h"
#pragma comment(lib,"shell32.lib")
//告诉编译器在编译形成的.obj文件和.exe文件中添加一条信息,使得连链接器在链接库时去直接找shell32.lib这个库,不要去找别的库
在相应的函数中添加如下代码
SHFILEOPSTRUCT fop;
fop.wFunc = FO_COPY;//选择执行类型,FO_COPY,FO_DELETE,FO_RENAME,FO_MOVE四种
fop.pFrom = _T(“C:\\a\0");//源文件夹的路径,以"\0"即空为结尾
fop.pTo = _T("C:\\b\0");//拷入文件的文件夹路径,以"\0"即空为结尾
SHFileOperation(&fop);
//现在就已经完成COPY功能,但是在COPY过程中,如果有相同的文件名,则会出现提示对话框
//如果不想出现提示框,则需要在SHFileOperation(&fop)前添加
//fop.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR;
//这样就不会显示提示窗口了。
// recusively copy file or directory from $src to $dst
void CopyFiles(const boost::filesystem::path &src, const boost::filesystem::path &dst)
{
if (! boost::filesystem::exists(dst))
{
boost::filesystem::create_directories(dst);
}
for (boost::filesystem::directory_iterator it(src); it != boost::filesystem::directory_iterator(); ++it)
{
const boost::filesystem::path newSrc = src / it->filename();
const boost::filesystem::path newDst = dst / it->filename();
if (boost::filesystem::is_directory(newSrc))
{
CopyFiles(newSrc, newDst);
}
else if (boost::filesystem::is_regular_file(newSrc))
{
boost::filesystem::copy_file(newSrc, newDst, boost::filesystem::copy_option::overwrite_if_exists);
}
else
{
_ftprintf(stderr, "Error: unrecognized file - %s", newSrc.string().c_str());
}
}
}