博客
关于我
c++ 复制文件到指定目录
阅读量:541 次
发布时间:2019-03-09

本文共 1040 字,大约阅读时间需要 3 分钟。

以下代码片段用于处理图片文件的存储路径与复制操作,适用于测试环境。

#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

 

以上代码片段实现了以下功能:
1. 设置输出目录为lpOutPutDir并添加"classified"标识
2. 将输出目录转换为字符串格式
3. 检查输出目录是否存在,若不存在则创建
4. 遍历图片存储路径列表
5. 为每张图片生成保存路径
6. 检查生成的保存路径是否存在,若不存在则创建
7. 复制源图片到目标路径
代码逻辑清晰,适用于批量处理图片文件的存储与复制操作。

转载地址:http://jtqiz.baihongyu.com/

你可能感兴趣的文章
Netty源码—5.Pipeline和Handler一
查看>>
Netty源码—5.Pipeline和Handler二
查看>>
Netty源码—6.ByteBuf原理一
查看>>
Netty源码—6.ByteBuf原理二
查看>>
Netty源码—7.ByteBuf原理三
查看>>
Netty源码—7.ByteBuf原理四
查看>>
Netty源码—8.编解码原理一
查看>>
Netty源码—8.编解码原理二
查看>>
Netty源码解读
查看>>
Netty的Socket编程详解-搭建服务端与客户端并进行数据传输
查看>>
Netty相关
查看>>
Netty遇到TCP发送缓冲区满了 写半包操作该如何处理
查看>>
Netty:ChannelPipeline和ChannelHandler为什么会鬼混在一起?
查看>>
Netty:原理架构解析
查看>>
Network Dissection:Quantifying Interpretability of Deep Visual Representations(深层视觉表征的量化解释)
查看>>
Network Sniffer and Connection Analyzer
查看>>
Network 灰鸽宝典【目录】
查看>>
NetworkX系列教程(11)-graph和其他数据格式转换
查看>>
Networkx读取军械调查-ITN综合传输网络?/读取GML文件
查看>>
network小学习
查看>>