Skip to content

Instantly share code, notes, and snippets.

@MarshySwamp
Last active February 6, 2024 00:26
Show Gist options
  • Save MarshySwamp/40aefebb39e0eef2d7599ac4050490d9 to your computer and use it in GitHub Desktop.
Save MarshySwamp/40aefebb39e0eef2d7599ac4050490d9 to your computer and use it in GitHub Desktop.
Code Snippet: Remove Filename Extension (3 different methods)
/* Remove Filename Extension (4 different methods) */
var baseName = app.activeDocument.name.split('.')[0];
// or for multiple period characters
var extensionIndex = activeDocument.name.lastIndexOf(".");
if (extensionIndex != -1) {
var baseName = activeDocument.name.substr(0, extensionIndex);
alert(baseName);
} else {
alert(activeDocument.name);
}
// or for multiple period characters
var docName = activeDocument.name.split('.');
docName.length --;
docName = docName.join('.');
alert(docName);
// or for multiple period characters
var baseName = app.activeDocument.name.replace(/\.[^\.]+$/, '');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment