Add string to file name

I have a loop which create graphics and save them into jpg files,
and save them as

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?


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)) {
else {

not tested

Warm regards,


1 Like

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

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

int num = 0;
color chosenColor;

void setup() {

void draw() {

void mouseClicked() {
  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");