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

If statement not working inside for loop for file saving?

Participant ,
Aug 09, 2015 Aug 09, 2015

Copy link to clipboard

Copied

Hello!

I have the following documents open in Photoshop:

123456_mrp_ou.tif

869548_mrp_ou.tif

896589_mrp_in.tif

896589_mrp_ou.tif

..and I have this if statement within a for loop to look for files with a specific "pid" number and save them in my Documents folder:

var originalPid = 896589

for(i = 0; i < app.documents.length ; i ++) {

      activeDocument = app.documents

        if(activeDocument.name.substring(0,6) === originalPid) {

                var standardSave = new File('/Users/constantincerdan/Documents/' + activeDocument.name)

                activeDocument.saveAs(standardSave, TiffSaveOptions, false, Extension.LOWERCASE)

}

}

This does not find the two files and save them when I run it. However, the for loop without the if statement runs just fine and saves all the documents into the Documents folder:

var originalPid = 896589

for(i = 0; i < app.documents.length ; i ++) {

      activeDocument = app.documents

                var standardSave = new File('/Users/constantincerdan/Documents/' + activeDocument.name)

                activeDocument.saveAs(standardSave, TiffSaveOptions, false, Extension.LOWERCASE)

}

How do I get it to work with an if statement so that it only saves those two?

Any help is much appreciated!

TOPICS
Actions and scripting

Views

295

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

Enthusiast , Aug 09, 2015 Aug 09, 2015

You are comparing apples with oranges, you need to compare strings.

originalPid = 896589;

alert(typeof originalPid);

Votes

Translate

Translate
Adobe
Enthusiast ,
Aug 09, 2015 Aug 09, 2015

Copy link to clipboard

Copied

You are comparing apples with oranges, you need to compare strings.

originalPid = 896589;

alert(typeof originalPid);

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
Participant ,
Aug 09, 2015 Aug 09, 2015

Copy link to clipboard

Copied

LATEST

Doh! How silly of me. I should have noticed this myself. Thank you, Philip.

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