I need to extract from these strings DHPH 1 and DHC 2527 and lose all the rest. I think I need to slice and I know where my first useful character is (the 36th character is the first I want to keep). I guess I also want to trim from before the SECOND space to the end. Can anyone help me with the string function syntax of this please…
// The string of the file path
var pathString = '/Users/thunder/Desktop/aaatest_run/DHC 2527 1472.jpg';
// Break the string down into an array using the slash as delimiter
var pathArray = pathString.split('/');
// get the last record of the array (Arrays are zero based)
var fileName = pathArray[pathArray.length-1];
// A word is a string delimited by a space, so commas and such are not used to determine a word
// Get word 1 to 2
var nameExtract = utils.stringMiddleWords(fileName, 1, 2)
application.output(nameExtract);
Ofcourse when you store the path of a file object already you can use the getName() function to get the filename of the whole path.
I assume this question is related to your previous image reading question. So your code would look something like this:
var theFolder = plugins.file.showDirectorySelectDialog();
if ( theFolder )
{
var theFolderContents = plugins.file.getFolderContents( theFolder, ['jpg','JPG']);
for ( var i = 0 ; i < theFolderContents.length ; i++ )
{
if ( theFolderContents[i].isFile() )
{
controller.newRecord();
myImageField = plugins.images.getImage(theFolderContents[i]);
myFileNameField = theFolderContents[i].getName();
myFilenameExtractField = utils.stringMiddleWords(myFileNameField, 1, 2)
}
}
}
var theFolder = plugins.file.showDirectorySelectDialog();
if (theFolder)
{
var theFolderContents = plugins.file.getFolderContents(theFolder, [‘jpg’,‘JPG’]);
for (var i = 0 ; i < theFolderContents.length ; i++)
{
if (theFolderContents*.isFile())*