本文介绍了如何在Windows-PC上用c ++复制非空目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
各位大家好!为此我有一个严重的问题,几个月前我已经写了一个文件复制非空目录给另一个,包括它的所有子文件。但这个函数是Recursive.anyone有更好的方法来解决这个功能?如果只是不使用递归!非常感谢!我将不胜感激,伙计们!
Hello, everybody! For this I have a serious problem, months ago I had written a File Copy non-empty directory to another,including its all children files.but this function is Recursive.anyone has a better way to resolve this function? if only not using recursive!Thank you very much! I will be appreciated,guys!
推荐答案
bool CopyNonEmptyFolder(const std::wstring& source_folder, const std::wstring& target_folder)
{
std::wstring new_sf = source_folder + L"\\*";
WCHAR sf[MAX_PATH + 1];
WCHAR tf[MAX_PATH + 1];
wcscpy_s(sf, MAX_PATH, new_sf.c_str());
wcscpy_s(tf, MAX_PATH, target_folder.c_str());
sf[lstrlenW(sf) + 1] = 0;
tf[lstrlenW(tf) + 1] = 0;
SHFILEOPSTRUCTW s = { 0 };
s.wFunc = FO_COPY;
s.pTo = tf;
s.pFrom = sf;
s.fFlags = FOF_SILENT | FOF_NOCONFIRMMKDIR | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NO_UI;
int res = SHFileOperationW(&s);
return res == 0;
}
这篇关于如何在Windows-PC上用c ++复制非空目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!