Skip to main content
kendalls84056349
Participant
May 16, 2020
Answered

Action for exporting with multiple output locations

  • May 16, 2020
  • 2 replies
  • 3179 views

I currently use a photoshop action to export jpegs at a smaller size. I am wondering if it is possible to edit the action to output the exported images into two different folders depending on file size. For example, after the action is run, files less than 200KB go into Folder A, while files larger than 200KB go into Folder B. I imagine this will take some scripting but I am unsure of how to approach this. Any guidance would be appreciated. 

This topic has been closed for replies.
Correct answer Charu Rajput

Hi, you can use following snippet that you needs to run separately. When you run this script, you have to choose folder where all jpg file exists. This script will create folder "Folder A" and "Folder B" for files less than or equal to 200KB and larger than 200 KB, respectively. Folder A and Folder B will be created inside the folder that you will choose. This is not may be exact answer that is required by you, but after running photoshop action, you can run this following script to filter the images based on sizes.

 

 

function main() {
    var folder = Folder.selectDialog("Select Folder");
    var files = folder.getFiles("*jpg");
    var smallFilesFolder = Folder(folder.fsName + "/Folder A");
    if (!smallFilesFolder.exists) {
        smallFilesFolder.create();
    }
    var largeFilesFolder = Folder(folder.fsName + "/Folder B");
    if (!largeFilesFolder.exists) {
        largeFilesFolder.create();
    }
    var len = files.length
    for (var i = 0; i < len; i++) {
        var _file = files[i];
        if (_file instanceof File) {
            if (_file.length <= 200000) { // less than equal to 200 KB
                _file.copy(smallFilesFolder + "/" + _file.name);
            } else if (_file.length > 200000) { // greater than 200 KB
                _file.copy(largeFilesFolder + "/" + _file.name);
            }
            _file.remove();
        }
    }
}

main();

 

 

I hope this helps you in an indirect way.

Thanks

2 replies

Charu Rajput
Community Expert
Charu RajputCommunity ExpertCorrect answer
Community Expert
May 17, 2020

Hi, you can use following snippet that you needs to run separately. When you run this script, you have to choose folder where all jpg file exists. This script will create folder "Folder A" and "Folder B" for files less than or equal to 200KB and larger than 200 KB, respectively. Folder A and Folder B will be created inside the folder that you will choose. This is not may be exact answer that is required by you, but after running photoshop action, you can run this following script to filter the images based on sizes.

 

 

function main() {
    var folder = Folder.selectDialog("Select Folder");
    var files = folder.getFiles("*jpg");
    var smallFilesFolder = Folder(folder.fsName + "/Folder A");
    if (!smallFilesFolder.exists) {
        smallFilesFolder.create();
    }
    var largeFilesFolder = Folder(folder.fsName + "/Folder B");
    if (!largeFilesFolder.exists) {
        largeFilesFolder.create();
    }
    var len = files.length
    for (var i = 0; i < len; i++) {
        var _file = files[i];
        if (_file instanceof File) {
            if (_file.length <= 200000) { // less than equal to 200 KB
                _file.copy(smallFilesFolder + "/" + _file.name);
            } else if (_file.length > 200000) { // greater than 200 KB
                _file.copy(largeFilesFolder + "/" + _file.name);
            }
            _file.remove();
        }
    }
}

main();

 

 

I hope this helps you in an indirect way.

Thanks

Best regards
Geppetto Luis
Legend
May 17, 2020

charu16
I have tried your script
There must be a mistake
puts all files in folder a
and those above 200kb
that less than 200kb

Charu Rajput
Community Expert
Community Expert
May 17, 2020

You are right, a small mistake was there. I have corrected the script.

Thankyou for pointing it out.

 

Best regards

Best regards
Stephen Marsh
Community Expert
Community Expert
May 16, 2020

This is not easy, as Photoshop has to estimate the final possibly compressed file size. Some scripts can keep saving, deleting and resaving a file until a specified threshold in file size is reached, which is very complex.

 

The Image Processor Pro script can save to multiple output locations, however, it is not based on final on-disk file size.

 

Good luck!