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,
Suresh.N
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)
Copy link to clipboard
Copied
Would
if (value < 10 || value > 19)
work?
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.
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.
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
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)
Copy link to clipboard
Copied
Here is yet another way to get the numbers.
var fileName = 'abcde-01.jpg' ;
alert(fileName.match(/\d+/));