Add string to file name

I have a loop which create graphics and save them into jpg files,
and save them as
saveFrame(“C:\process\test\colors-###.jpg”);

I create the graphics from randomize list of colors, and if the color red was chosen,
I want the file to be saved as colors-###-red.jpg

Is that possible?

Hello,

what about colors-red-###.jpg ? Might be easier. (the other thing is also possible)

Than you only need an if-clause to distinguish I guess:

if(chosenColor==color(255,0,0)) {
   saveFrame(“C:\process\test\colors-red-###.jpg”);
}
else {
   saveFrame(“C:\process\test\colors-###.jpg”);
}

not tested

Warm regards,

Chrisir

2 Likes

Thanks for your reply, but it won’t do the job I need, because it will change the order of the files,
but I got an idea for different problem I had, in different project, so… thanks :slight_smile:

1 Like

You can sort by date

But you can of course make another way to enumerate the files

Instead of using the inbuilt automatically numeration

1 Like

sort by date won’t help cause I need to upload them to a platform sort only by name

However, if I am using my own variable,
Is there an option to use string as a file name?

Tested on macos

//global
int num = 0;
color chosenColor;

void setup() {
  
  size(200,299);
  
}

void draw() {
  
}

void mouseClicked() {
  
  //local
  num++;
  String dir = "path/to/dir/";
  
  if(chosenColor==color(255,0,0)) {
     saveFrame(dir + "colors-" + nf(num, 3) + "-red.jpg");
  }
  else {
     saveFrame(dir + "colors-" + nf(num, 3) + ".jpg");
  }


}
2 Likes