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

Automatically Validate Input Count vs. Output

Community Expert ,
Feb 23, 2021 Feb 23, 2021

Copy link to clipboard

Copied

I have a script that currently uses manual validation, however, I'd like to automate the check, however, I don't now how to do so.
 
inputCount is the variable for the files found in an input folder.
 
setQty is the variable for a division of the inputCount.
 
One can be divided into the other:
 
inputCount / setQty
 
For exaple, if the input folder has 10 images and the quantity of sets is 2, then the result is 5 which is an integer and evenly divisible into the source of 10 images. The input count value may change, it could be an odd or even value of any length. The setQty value may change, it could be an odd or even number of any length, it should evenly divide into the inputCount.
 
If the input folder had 7 images, divided by a set quantity of 2, the result would be 3.5 which is not an integer and not evenly divisible by the set qty of 2.
 
Currently I have a confirmation dialog set to notify the user, however, this obviously relies on the user to make a judgement call.  
TOPICS
Actions and scripting

Views

417

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

LEGEND , Feb 23, 2021 Feb 23, 2021

What should be correct number for that example, 1 or 7?

 

i = 1; while(7 % ++i); i

 

or:

 

i = j = 7; while(j % --i); i

 

Or else you want:

 

!(7 % 2)

 

so:

 

!(20 % 4)

 

Votes

Translate

Translate
Adobe
LEGEND ,
Feb 23, 2021 Feb 23, 2021

Copy link to clipboard

Copied

What is preferred result for above example, 3 and 4?

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 ,
Feb 23, 2021 Feb 23, 2021

Copy link to clipboard

Copied

What is preferred result for above example, 3 and 4?


By @Kukurykus

 

 

Thank you for the reply.

 

Neither is preferred. I was thinking of a conditional or try/catch error to cancel the script if the input length is not evenly divisible by the set length. 

 

I don't know how to express it better...

 

To pass, the number must be an integer.

To pass, the input count has to divide into "sets".

 

If there were 33 input files batched in sets of 3, the result is 11 which is a pass. 32 or 34 input files divided by 3 would fail.

 

If there were 20 input files batched in sets of 4, the result is 5, which is a pass. 19 or 21 input files would be a fail when divided by 4.

 

The division number could be odd or even, however, it is always an integer. The input count is also an integer (as one can't have less than a single file) and could be odd or even.

 

Hope this makes sense.

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
LEGEND ,
Feb 23, 2021 Feb 23, 2021

Copy link to clipboard

Copied

What should be correct number for that example, 1 or 7?

 

i = 1; while(7 % ++i); i

 

or:

 

i = j = 7; while(j % --i); i

 

Or else you want:

 

!(7 % 2)

 

so:

 

!(20 % 4)

 

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 ,
Feb 23, 2021 Feb 23, 2021

Copy link to clipboard

Copied

Haha, I'm lost! Thank you for sticking with me... Math is not my strong area.

 

The correct answer is an integer, that is cleanly divided from the input from the sets. This is dependent on both variables, will will depend on an unkown length of input images and an uknown set value which divides into thje input length.

 

Am I over thinking this? If the calculated division number is not an integer the script should cancel/fail/exit. Is testing to see if the set evenly divides into the input length redundant?

 

At the moment the manual check is:

 

            // Manually validate the input count vs. output count
            var inputCount = fileList.length;
            var cancelScript = confirm(inputCount + " input files stacked into sets of " + setQty + " will produce " + inputCount / setQty + " file sets. Press 'Yes' to continue or 'No' to cancel.");
            // Test if no returns false, then terminate the script
            if (cancelScript === false) {
                alert('Script cancelled!');
                return;
            }

 

 

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
LEGEND ,
Feb 23, 2021 Feb 23, 2021

Copy link to clipboard

Copied

I updated my post of that you probably look for.

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 ,
Feb 23, 2021 Feb 23, 2021

Copy link to clipboard

Copied

Thank you!

 

Keeping in mind that I only know enough about scripting to be dangerous... I am testing your suggestion:

 

var inputCount = 20;
var setQty = 4;
var theResult = !(inputCount % setQty);
alert(theResult);

  

Which reslts in True!

 

var inputCount = 19;
var setQty = 4;
var theResult = !(inputCount % setQty);
alert(theResult);

 

Results in False...

 

This is looking promising, thank you, now all I need to do is work out how to construct the try/catch or if/else.

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
LEGEND ,
Feb 23, 2021 Feb 23, 2021

Copy link to clipboard

Copied

 

inputCount = 20, setQty = 4, inputCount % setQty ? 'exit' : 'enter'

 

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 ,
Feb 23, 2021 Feb 23, 2021

Copy link to clipboard

Copied

This is what I came up with as I just repurposed my previous manual check:

 

// Validate the input count vs. output count
var inputCount = fileList.length;
// Thanks to Kukurykus for the % 
var cancelScript = !(inputCount % setQty);
alert(inputCount + ' input files stacked into sets of ' + setQty + ' will produce ' + inputCount / setQty + ' file sets.');
// Test if false, then terminate the script
if (cancelScript === false) {
    alert('Script cancelled as the quantity of input files are not evenly divisible by the set quantity.');
    return;
}

 

I'll look into your suggestion, thank you!

 

Now I need to go find what the % operator does.

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
LEGEND ,
Feb 23, 2021 Feb 23, 2021

Copy link to clipboard

Copied

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 ,
Feb 23, 2021 Feb 23, 2021

Copy link to clipboard

Copied

LATEST

Thank you, I found it here as well under modulus/remainder:

 

https://www.w3schools.com/js/js_arithmetic.asp

 

However without your help that would have been a major stretch from the "textbook answer" to a "working answer".

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