arrar and copy files

Dear sir:

I have a sequence image files: from box0001.jpg to box0015.jpg, I want to
cut box0001.jpg - box0009.jpg to a folder(C:/box1/), and cut box0011.jpg - box0015.jpg to another folder (C:/box2/), how do I use array and a loop to do this?

Can someone help? Thanks a lot!

Sincerely yours
Ze Yi Hsu
For such purposes a script would be better than a program.
http://en.wikipedia.org/wiki/Batch_file
http://en.wikipedia.org/wiki/Shell_script

Anyway, in a for() loop you would use:
http://cplusplus.com/reference/cstdio/rename/
http://cplusplus.com/reference/cstdio/sprintf/

You need sprintf() to build the filename string from the current index in the for() loop.
Dear Catfish3:

Thanks a lot!
Best
Ze Yi Hsu
Dear catfish3:
Sorry to bother you again,
If using program, how do I choose box0001.jpg to box0015.jpg by using
arrar, I dont want to write like this;
box[ ]={box0001.jpg, box0002.jpg,box0003.jpg....}
because the image files might be a lot??
I want to give a range, such as 1-15, or 16-200...etc
how do I make array by using the range?

Best
Ze-Yi Hsu
Use the sprintf() function to create the arrays (not arrar, but array).

This is the traditional way (like how it can be done in C language, not just C++).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <cstdio>
using namespace std;

int main()
{
	char tempFilename[100];

	for (int i=1; i <= 14; ++i)
	{
		sprintf(tempFilename, "box%04d.jpg", i);
		printf("%s\n", tempFilename);
	}
}
box0001.jpg
box0002.jpg
box0003.jpg
box0004.jpg
box0005.jpg
box0006.jpg
box0007.jpg
box0008.jpg
box0009.jpg
box0010.jpg
box0011.jpg
box0012.jpg
box0013.jpg
box0014.jpg


The new way is by using string streams.
http://cplusplus.com/reference/sstream/

But I have to see your current source code (written program) to understand which way is better for you.
Dear catfish3:

Thanks!
This is a big help!

Best
ze-Yi Hsu
Topic archived. No new replies allowed.