Repository: AUTOMATIC1111/stable-diffusion-webui

Issue:
Request: something akin to a batch ID for folder name pattern
**Is your feature request related to a problem? Please describe.**
I've been experimenting with the wildcards script linked in the wiki lately.
It's wonderful but unfortunately, it's wreaking havoc on the folder structure in my outputs/txt2img-images folder since every single image of a batch is likely to have a different prompt. 

Another problem this feature request would solve is when you run the same prompt (or at least similar start) multiple times. With the current filename patterns available, multiple batches are all sorted in the same folder. This is, admittedly, not a huge annoyance to most users, but it can be an issue or at least unexpected behavior when your prompt from today gets sorted into a folder from 3 days ago because you reused a prompt.

**Describe the solution you'd like**
Generate an ID when starting a batch and make that available as a folder name pattern.  
I don't care much about how that ID is formatted. I'd be fine with a random string of, let's say, 5 hexadecimal characters.

**Describe alternatives you've considered**
I don't believe there is a suitable alternative that allows a user to have images grouped by batch that does not have the potential to include images from other batches accidentally. At least not with the current file/directory patterns available.

**Additional context**
All of these are from just one wildcard batch of 20, all containing just a single image. 
![](https://i.imgur.com/8CXxtsO.png)

My output directory pattern is set up in such a way that I have a folder for every day. As you can see, the subfolder just for *today* has >1000 subfolders. It's hard to keep track of things like this.
![](https://i.imgur.com/6u2v0Hu.png)



Discussion:

Resolving patch:
diff --git a/modules/images.py b/modules/images.py
--- a/modules/images.py
+++ b/modules/images.py
@@ -295,6 +295,7 @@ def apply_filename_pattern(x, p, seed, prompt):
 
     x = x.replace("[model_hash]", shared.sd_model.sd_model_hash)
     x = x.replace("[date]", datetime.date.today().isoformat())
+    x = x.replace("[job_timestamp]", shared.state.job_timestamp)
 
     if cmd_opts.hide_ui_dir_config:
         x = re.sub(r'^[\\/]+|\.{2,}[\\/]+|[\\/]+\.{2,}', '', x)
diff --git a/modules/shared.py b/modules/shared.py
--- a/modules/shared.py
+++ b/modules/shared.py
@@ -4,6 +4,7 @@
 import os
 import gradio as gr
 import tqdm
+import datetime
 
 import modules.artists
 from modules.paths import script_path, sd_path
@@ -65,6 +66,7 @@ class State:
     job = ""
     job_no = 0
     job_count = 0
+    job_timestamp = 0
     sampling_step = 0
     sampling_steps = 0
     current_latent = None
@@ -78,6 +80,8 @@ def nextjob(self):
         self.job_no += 1
         self.sampling_step = 0
         self.current_image_sampling_step = 0
+    def get_job_timestamp(self):
+        return datetime.datetime.now().strftime("%Y%m%d%H%M%S")
 
 
 state = State()
diff --git a/webui.py b/webui.py
--- a/webui.py
+++ b/webui.py
@@ -50,6 +50,7 @@ def f(*args, **kwargs):
         shared.state.sampling_step = 0
         shared.state.job_count = -1
         shared.state.job_no = 0
+        shared.state.job_timestamp = shared.state.get_job_timestamp()
         shared.state.current_latent = None
         shared.state.current_image = None
         shared.state.current_image_sampling_step = 0


Test patch: