# How to check if there is an image with the same file name?

**URL:** <https://discourse.processing.org/t/how-to-check-if-there-is-an-image-with-the-same-file-name/27336>\
**Category:** Coding Questions\
**Created:** [January 24, 2021, 3:49pm UTC](https://discourse.processing.org/t/how-to-check-if-there-is-an-image-with-the-same-file-name/27336 "2021-01-24T15:49:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lukerfull](https://avatars.discourse-cdn.com/v4/letter/l/6a8cbe/32.png) [@Lukerfull](https://discourse.processing.org/u/Lukerfull)\
**Post date:** [January 24, 2021, 3:49pm UTC](https://discourse.processing.org/t/how-to-check-if-there-is-an-image-with-the-same-file-name/27336/1 "2021-01-24T15:49:48Z")

</div>

I want to save images without overwriting them. This is my code:

```auto
  if (controlDown) {
    if (keyCode == 83) {  
      PImage partialSave = get(0,0,1098,650);
      nimg++;
      partialSave.save("drawings/draw"+nimg+".jpg");
    }

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 24, 2021, 4:07pm UTC](https://discourse.processing.org/t/how-to-check-if-there-is-an-image-with-the-same-file-name/27336/2 "2021-01-24T16:07:10Z")

</div>

> [@Timer with specific format](https://discourse.processing.org/t/timer-with-specific-format/6864/3):
>
> nf() -\> [Processing.org/reference/nf\_.html](http://Processing.org/reference/nf_.html)[Forum.Processing.org/two/discussion/16001/add-0-s-to-date-time-in-the-filename-with-saveframe#Item\_3](http://Forum.Processing.org/two/discussion/16001/add-0-s-to-date-time-in-the-filename-with-saveframe#Item_3) SimpleDateFormat -\> [Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/text/SimpleDateFormat.html](http://Docs.Oracle.com/en/java/javase/11/docs/api/java.base/java/text/SimpleDateFormat.html)[Forum.Processing.org/two/discussion/10067/how-to-prevent-file-overwriting#Item\_3](http://Forum.Processing.org/two/discussion/10067/how-to-prevent-file-overwriting#Item_3)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 24, 2021, 5:11pm UTC](https://discourse.processing.org/t/how-to-check-if-there-is-an-image-with-the-same-file-name/27336/3 "2021-01-24T17:11:04Z")

</div>

Is this a question? Does it work?

It would work, imho

But when you start your Sketch anew (new session ), the old images would be overwritten

So let the Sketch check the last highest number first

---

<div class="post-metadata">

**Author:** ![Lukerfull](https://avatars.discourse-cdn.com/v4/letter/l/6a8cbe/32.png) [@Lukerfull](https://discourse.processing.org/u/Lukerfull)\
**Post date:** [January 24, 2021, 5:23pm UTC](https://discourse.processing.org/t/how-to-check-if-there-is-an-image-with-the-same-file-name/27336/4 "2021-01-24T17:23:42Z")

</div>

That’s what I’m asking, how can i check the highest number?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 24, 2021, 8:24pm UTC](https://discourse.processing.org/t/how-to-check-if-there-is-an-image-with-the-same-file-name/27336/5 "2021-01-24T20:24:15Z")

</div>

Check out the post from gotoloop please

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [January 24, 2021, 8:28pm UTC](https://discourse.processing.org/t/how-to-check-if-there-is-an-image-with-the-same-file-name/27336/6 "2021-01-24T20:28:07Z")

</div>

In theory you can use fileList scan all names and receive the highest number by a search

Then add +1

---

<div class="post-metadata">

**Author:** ![Lukerfull](https://avatars.discourse-cdn.com/v4/letter/l/6a8cbe/32.png) [@Lukerfull](https://discourse.processing.org/u/Lukerfull)\
**Post date:** [January 24, 2021, 8:44pm UTC](https://discourse.processing.org/t/how-to-check-if-there-is-an-image-with-the-same-file-name/27336/7 "2021-01-24T20:44:12Z")

</div>

fileList worked!!, ty all!
