阅读背景:

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

来源:互联网 

代码如下:

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;
}int main()
{
	for (int i = 1; i <= 7



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: