您的位置:首页 > 其它

将一个文件夹中的图片移动到另一个文件夹,并重命名

2017-09-12 15:54 204 查看
代码如下:

int main()
{
for (int i = 1; i <= 7; i++)
{
for (int j = 1; j <= 38; j++){
if (j <= 9){
string path1 = "C:\\Users\\Zender\\Desktop\\object\\" + to_string(i) + "\\cam_0" + to_string(j) + ".png";//原图片所在路径
string path2 = "C:\\Users\\Zender\\Desktop\\object\\cam_0" + to_string(j) + "\\" + to_string(i) + ".png";//存储图片的新路径
cout << path1 << endl;
if (rename(path1.c_str(), path2.c_str()) != 0)
//nt rename(const char *oldname, const char *newname);如果oldname为一个文件而不是目录,那么为该文件更名。
cout << "fail" << endl;
}
else {
string path3 = "C:\\Users\\Zender\\Desktop\\object\\" + to_string(i) + "\\cam_" + to_string(j) + ".png";
string path4 = "C:\\Users\\Zender\\Desktop\\object\\cam_" + to_string(j) + "\\" + to_string(i) + ".png";
cout << path3 << endl;
if (rename(path3.c_str(), path4.c_str()) != 0)
cout << "fail" << endl;
}
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐