• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
8

How does Automate/Batch handle Source image file order when processing?

Explorer ,
Dec 11, 2023 Dec 11, 2023

Copy link to clipboard

Copied

Hello,

 

This question concerns Win 11 Photoshop Batch and Action commands.

 

I resized about 7000 image files, numbered like this: 0000_FIXED, 0000_MOVING, 0001_FIXED, 0001_MOVING, using a simple one operation Action that applied Image Size to each image, and set up Batch to read the input files and save the output files to a new folder.

 

Photoshop couldn't handle that operation on that many files at one go, and gives an out-of-memory error part way through. I solved this problem by deleting the input files that had "made it" through the Batch and then restarting the Batch, specifying the correct "Starting Serial #" for the first of the remaining output files in the Destination section of the Batch dialog.

 

The first time I tried this without deleting the "done" files in the Source folder on disk, I had assumed the "Starting Serial #" value would also apply to the input files in the Source section of the Batch dialog. However, that was just wishful thinking, and it started over using the "0000_FIXED.png" input file, but named the output file starting with the "Starting Serial #" I'd supplied.

 

The solution of deleting the "done" files in the Source folder, supplying the proper "Starting Serial #" for the rest of the output files, and restarting the Batch worked, in its kludgy fashion, but it made me wonder how the Batch command sees and orders the Source files.

 

As you know, the order of files on the hard drive often does not match their file name order as seen in Explorer. In this case, the file names show up in numerical order by name (0000_FIXED, 0000_MOVING, 0001_FIXED, 0001_MOVING, etc.) in Explorer but they may be in a more random order on the hard drive.

 

So, my question is how does the Batch command see and order the files in the Source folder? Does it follow the order as displayed in Windows in Explorer, does it look for a numbering scheme and if that exists follow that instead, or what?

 

Also, what if the Source files are not named with numerically-ordered suffixes, in what order will Batch process them? Certainly not alphabetically, I trust ...

 

Last question, how is it that Photoshop, after all these decades, still often retains handles to files and folders that it has opened and that have been closed, necessitating Photoshop being shut down in order to rename/delete/move those files/folders in Windows?

 

Thanks very much for any insights to this.

 

Ian J.

TOPICS
Actions and scripting , Windows

Views

141

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 11, 2023 Dec 11, 2023

The following script will write the date/time and filename of each processed file to a log file.

 

There must be a file named 'batch-log.txt' on the Desktop.


A file must be opened when recording this script as an action step to create a log file for use with the File > Automate > Batch command.

 

/*
Batch Logger.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-does-automate-batch-handle-source-image-file-order-when-processing/td-p/14292163
v1.0 - 12th December 2023, Stephen
...

Votes

Translate

Translate
Adobe
Community Expert ,
Dec 11, 2023 Dec 11, 2023

Copy link to clipboard

Copied

@Ian Jaffray 

 

Perhaps this link will help you to answer your question:

 

 
The script could be adjusted to write to a single log file, rather than creating a separate log file for each image processed via batch. EDIT: See the new code below...
 
I believe that the sort order is numeric/alphabetical. I seem to recall that Mac and Win OS have a slightly different idea of what this means, however, I can't recall the specifics. If I am writing cross-platform scripts that rely on file order, then I use JavaScript .sort() or .sort().reverse() to enforce cross-platform file processing.
 
It is always best to start with unique zero padded numbers in filenames if one wishes to enforce a specific processing order.
 
Adobe Bridge can preserve the original filename as metadata in each file. Then, batch rename files with a leading zero padded sequence to force a sort order. After processing a batch, Adobe Bridge can then be used to restore the original filenames from the preserved filename metadata.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 11, 2023 Dec 11, 2023

Copy link to clipboard

Copied

The following script will write the date/time and filename of each processed file to a log file.

 

There must be a file named 'batch-log.txt' on the Desktop.


A file must be opened when recording this script as an action step to create a log file for use with the File > Automate > Batch command.

 

/*
Batch Logger.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-does-automate-batch-handle-source-image-file-order-when-processing/td-p/14292163
v1.0 - 12th December 2023, Stephen Marsh
Info: There must be a file named 'batch-log.txt' on the Desktop.
      A file must be opened when recording this script as an action step to create a log file for use with the File > Automate > Batch command.
*/

#target photoshop

var thePath = "~/Desktop";
var theName = activeDocument.name.replace(/\.[^\.]+$/, '');
var dateTime = new Date().toLocaleString();
var logFile = new File(thePath + "/" + 'batch-log.txt');

if (logFile.exists) {
    try {
        var os = $.os.toLowerCase().indexOf("mac") >= 0 ? "mac" : "windows";
        if (os === "mac") {
            logFileLF = "Unix";
        } else {
            logFileLF = "Windows";
        }

        logFile.open("a");
        logFile.encoding = "UTF-8";
        logFile.lineFeed = logFileLF;
        logFile.write(dateTime + "\r" + activeDocument.name + "\r");
        logFile.close();

    } catch (e) {
        //alert(e + ': Line ' + e.line);
    }
} else {
    alert("The 'batch-log.txt' file can't be found on the: " + thePath);
}

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 27, 2023 Dec 27, 2023

Copy link to clipboard

Copied

LATEST

Thanks for your reply to this question, Stephen, and I apologize for my late "Marked as Correct Answer."

 

I still haven't had time to test your answer, but given my experience with how Batch functioned for me, I believe you're correct. "Alphanumeric" sort order is probably the case, and so it treats numeric prefixes (like "0000", "0001", etc.) correctly. You're point to use numeric prefixes to force order is a good one and I can confirm that that works. I was asking specifically about how Batch sees the file order in a folder, but I appreciate the code as well.

Thanks!

Ian J.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines