Last active
February 6, 2024 00:26
-
-
Save MarshySwamp/40aefebb39e0eef2d7599ac4050490d9 to your computer and use it in GitHub Desktop.
Code Snippet: Remove Filename Extension (3 different methods)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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