Is it possible to create an if statment with dynamic logical tests? For example, I have a .csv file that has a file name in the first column, and the columns after that have random tag data. The first row of the .csv is a header (so it's pretty much just ignored), the second row is the file and tags to be compared to the others, the third row is the header for the file name column and all of the tag category columns after that, and below that are all the files and their tags to be compare row 2 to. The problem is, not every category of files has the same number of tags, and not all tags may be necessary for the comparison, so I was going to have a dialog window of checkboxes come up listing the header row's non-null tag columns as individual checkboxes. The if statement would then need to compare all of the selected columns to the other listed files (the on row 4 and below) to find any that contain the exact same tags as the source file (the one in row 2).

Seems I've come up with a stumper. I'm not even sure if this is doable, but if anyone has any ideas or knows if it's doable or not; let me know. The script basically just needs to check for files whose tags match the first file's tags and open them in Photoshop so we can compare and get rid of any duplicates. The biggest obstacle being the random number of tag categories per file category.

Hey Michael, thanks for the reply. The array labelled "baseTag" holds the data for a single row in a .csv file (for simplicity, we'll say it's the very first row). The array labelled "tag" holds the data for all the remaining rows of the .csv file. So for example, the .csv might look something like below when opened with a spreadsheet program:

File Name

Tag1

Tag2

Tag3

FileName1.format

wood

dark

strong

FileName2.format

wood

light

strong

FileName3.format

wood

medium

light

FileName4.format

wood

dark

strong

FileName1.format is the file we're doing the check on using the tag columns to the right, and if it finds a match using those tags, it opens the file listed in column 1. So the script would need to make sure all tags match the first row's tags (in this example, only FileName4.format would match FileName1.format's tags). However, there may be instances where I wish to exclude one of the columns from the check (for example, only check for matches of tag 1 and 3). So this would require that the if statement's check only look for matches of the tag1 and tag3 columns while ignoring Tag2 (so now FileName2.format would also match). Essentially, instead of being:

The issue I'm having is making this change to the if statement be dynamic (without a huge mess of inefficient code). Your mention of a switch statement sounds interesting. I'm not the greatest programmer yet (pretty much just the really basic stuff) so I hadn't heard about this statement yet; but I'll certainly be looking it up now. Anyway, hope the info helps clarify it a little better.

You have have if statement that uses the AND operator. In order for that to test true all the expressions need to test true. So for each expression you create another set of expression that uses the OR operator. With the OR operator if either are true it test true.

So if you want baseTag[1] == tag[1] to test true if tag1 is false( skip this tag ) you create an expression that will test true if tag1 == false. !tag1 || baseTag[1] == tag[1] You then wrap with () so it makes one expression as part of your AND comparisons

Well, it was a tough call, but both methods worked quite well. Michael's method was a little easier to implement, while Paul's was a little bit more dynamic. As a result, I decide to give the "Correct" answer credit to Paul, though both are technically correct (if I could give it to 2 people, I would!). Thanks again for the help guys! It is very much appreciated!

Edit: The thing that makes Pauls more dynamic is the ability to incorporate it with a for loop so that the length can be determined by an array's length, where as the other method is easier to implement, but limited to the scope of the defined if statement.