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

Finding only Alphabets in File name

New Here ,
Jan 10, 2017 Jan 10, 2017

Copy link to clipboard

Copied

Hi,

I am trying to find if any alphabets comes in the file name i should get an alert. As well as only numbers also i need to make a script.

I tried writing the code like this:

It storing the file name. But not getting alert !!!!

Does any one help on this.

#target photoshop

var myInputFolder = Folder.selectDialog ("Select Web Folder");

if(myInputFolder!=null){

    var myFiles = myInputFolder.getFiles(/\.(tif)$/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;

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

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

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

   

    alert(imageNum)

    }

}

}

I am getting before "-" file name in alert. But not throwing error if file name contains Alphabets.

Thanks in Advance,

Suresh.

TOPICS
Actions and scripting

Views

301

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

Engaged , Jan 10, 2017 Jan 10, 2017

Hi Suresh,

use this code..

if (/[a-zA-Z]/.test(fileNameNoExt)) { alert('Letter Found')}

else{ alert('Number Found')}

Instead of

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

    alert(fileNameNoExt)

-yajiv

Votes

Translate

Translate
Adobe
Engaged ,
Jan 10, 2017 Jan 10, 2017

Copy link to clipboard

Copied

LATEST

Hi Suresh,

use this code..

if (/[a-zA-Z]/.test(fileNameNoExt)) { alert('Letter Found')}

else{ alert('Number Found')}

Instead of

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

    alert(fileNameNoExt)

-yajiv

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