c++ 复制文件到指定目录

 

代码如下:

#if 1 //仅供测试用
    wstring  strsavepath = lpOutPutDir;
    strsavepath += L"classified";
    string imgsavepath = StringConvert::ws2s(strsavepath);
    const char* dir = imgsavepath.c_str();
    if (_access(dir, 0) == -1)
    {
        _mkdir(dir);
    }
    for (int i = 0; i < m_ImgPath.size(); i++)
    {
        string saveimgfilepath = imgsavepath +"\\"+ to_string(m_vecImgFlagOut[i]);
        const char* dir = saveimgfilepath.c_str();
        if (_access(dir, 0) == -1)
        {
            _mkdir(dir);
        }
        //执行复制操作
        wstring srcimgfilepath = m_ImgPath[i];
        string::size_type iPos = srcimgfilepath.find_last_of('\\') + 1;
        wstring filename = srcimgfilepath.substr(iPos, srcimgfilepath.length() - iPos);
        wstring dstimgfilepath = StringConvert::s2ws(saveimgfilepath)+L"\\" + filename;
        CopyFileW(srcimgfilepath.c_str(), dstimgfilepath.c_str(), FALSE);
    }
    
#endif

 

posted @ 2020-08-26 16:27  巨鹿王十二  阅读(2805)  评论(0编辑  收藏  举报