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

Catch wrong file name in a folder by script

New Here ,
Apr 22, 2015 Apr 22, 2015

Copy link to clipboard

Copied

Hi,

I want to write a code for to catch only in file name at the end.

I tried to write my script like this:

#target photoshop

var myInputFolder = Folder.selectDialog ("INPUT");

if(myInputFolder!=null){

    var myFiles = myInputFolder.getFiles(/\.(jpg|psd|tif|png|gif)$/i);

    for(var fileIndex=0;fileIndex<myFiles.length;fileIndex++)

    {

        var currentFile = myFiles[fileIndex];

        if(currentFile instanceof File)

        {

                if(currentFile.hidden) continue;

                    var doc = app.open(currentFile);

        myDoc = doc.name;

        value = myDoc.slice(8,-4);

        if(value !=10)

        {

            alert(" File naming conversion should be -10");

        }

//Here i want to write some more code

}

}

}

here i want to write if value is in between 10 to 19(E.g., 10, 11, 12, 13, 14, 15, 16, 17, 18, 19) the code should skip the alert. How to write the code.

Thanks in advance,

12345664.JPG

Suresh.N

TOPICS
Actions and scripting

Views

439

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 , Apr 22, 2015 Apr 22, 2015

Here's a little script that will get just the numbers of the file name after the dash and change it to a number:

#target photoshop

var fileName = 'abcde-01.jpg'

var fileNameNoExt = fileName.split('.')[0];

var dashIndex = fileNameNoExt.split('-');

var imageNum = Number(fileNameNoExt.split('-')[dashIndex.length-1])

alert(imageNum)

Votes

Translate

Translate
Adobe
Community Expert ,
Apr 22, 2015 Apr 22, 2015

Copy link to clipboard

Copied

Would

        if (value < 10 || value > 19)

work?

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
New Here ,
Apr 22, 2015 Apr 22, 2015

Copy link to clipboard

Copied

Hi,

Thanks for suggessions. With your suggession script is working fine for now. But Instead of splitting the file name with mask, is there any way other way to read file name. If Yes, Please suggest.


myDoc = doc.name;

        value = myDoc.slice(8,-4); // here the no 8 values may vary some times. how to avoid this problems.

some times the file name varies (abcdefg may change to abcd or abcdefgh )

Suresh.

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 ,
Apr 22, 2015 Apr 22, 2015

Copy link to clipboard

Copied

Also be aware that when you're splitting the file name those numbers are actually strings and need to be converted to a number for c.pfaffenbichler's good suggestion to work.

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
New Here ,
Apr 22, 2015 Apr 22, 2015

Copy link to clipboard

Copied

I found some script on web.

Is it helpful to solve my problem.

The script follows:

File.prototype.nameWithoutExtension = function() {

var fullName = this.name

var finalDotPosition = fullName.lastIndexOf( "." ) ;

if ( finalDotPosition > -1 ) {

  return fullName.substr( 0 , finalDotPosition );

}

return fullName ;

}

Please suggest.

Thanks

suresh

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 ,
Apr 22, 2015 Apr 22, 2015

Copy link to clipboard

Copied

Here's a little script that will get just the numbers of the file name after the dash and change it to a number:

#target photoshop

var fileName = 'abcde-01.jpg'

var fileNameNoExt = fileName.split('.')[0];

var dashIndex = fileNameNoExt.split('-');

var imageNum = Number(fileNameNoExt.split('-')[dashIndex.length-1])

alert(imageNum)

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
Enthusiast ,
Apr 22, 2015 Apr 22, 2015

Copy link to clipboard

Copied

LATEST

Here is yet another way to get the numbers.

var fileName = 'abcde-01.jpg' ;

alert(fileName.match(/\d+/));

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