0

I hope someone can help / I can explain this properly.

I have a script for Photoshop, kindly written many years ago, exporting a bunch of jpegs of different sizes from a psd.

The files exported have a suffix to denote size (e.g. from jacket-3.psd we get jacket-1s.jpg, jacket-3m.jpg, and jacket-3xs.jpg).

The relevant parts of the script for this are:

ExportSizes = [
  { 'width': 300, 'suffix': 'xs' },  
];

newFileName = subFolderText + fileNameNoPathClean + ExportSizes[i].suffix + '.jpg';

I wish now to also export a file with the name jacket-shop-3.jpg -- i.e. with the string "shop-" inserted into the original filename rather than just a suffix.

Can anyone please advise how this can be done?

Paul Vincent
  • 43
  • 1
  • 9
  • 1
    What's wrong with `newFileName = subFolderText + fileNameNoPathClean + "shop-" + ".jpg";` – Ghoul Fool Oct 31 '21 at 06:40
  • Also see [this post on removing file extensions](https://stackoverflow.com/questions/4250364/how-to-trim-a-file-extension-from-a-string-in-javascript) – Ghoul Fool Nov 02 '21 at 17:22

1 Answers1

1

Using the pieces of your example,

var ExportSizes = [
  { 'width': 300, 'suffix': 'xs' },  
];

var i = 0;
var subFolderText = "C:\\somefolder\\";
var fileNameNoPathClean = "jacket-3.psd";

// Use a regular expression to remove the extension.
var regEx = new RegExp(/(\.\w{1,}$)/gim);
fileNameNoPathClean = fileNameNoPathClean.replace(regEx, "");
// add "shop-" to the string
fileNameNoPathClean += "shop-";

var newFileName = subFolderText + fileNameNoPathClean + ExportSizes[i].suffix + '.jpg';

alert(newFileName);
Ghoul Fool
  • 6,249
  • 10
  • 67
  • 125