How to save an image without overwriting old ones when re-running the sketch
in
Programming Questions
•
1 year ago
Hello,
I've been working on a project and I am a little bit blocked.
I've put the next code for saving images on the " Images " folder when s (or S) is pressed:
-
int imageCount;
if (keyPressed){if (key == 's' || key == 'S'){imageCount++;save("Images/" + "Picture-" + imageCount + ".png");}}
It works perfectly fine but I was wondering if it's possible to save the images without overwriting the ones that I saved the last time I ran the sketch.
For instance, if I run the sketch one time and I save 3 images, they will be named Picture-1, Picture-2 and Picture-3 and will be saved on the Image folder, but if I run the sketch a second time and I want to save, lets say, 2 more images, they will also be named Picture-1 and Picture-2 and will be placed on the same Image folder, which means they will overwrite the first Picture-1 and Picture-2 I saved before... I would like them to be called Picture -4 and Picture -5 or to be placed on a new folder named Images-2 or something like that.
So my question is, is this possible to create a new folder each time I run the sketch with different names? Or is it possible to know how many images there is on my folder in order to do something like this:
- imageCount = *number of images on the folder*++;
1