• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
1

Document name without file extension [via script]

Engaged ,
Jan 06, 2024 Jan 06, 2024

Copy link to clipboard

Copied

If possible, I would like to have the name of the document without the .jpg or .tif extension
I would just like the name
this is the starting file
thanks to who helps me

 

 

dName = activeDocument.name;alert(dName);

 

 

TOPICS
Actions and scripting

Views

282

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jan 06, 2024 Jan 06, 2024

@Ciccillotto 

 

You should be able to find examples of this on the forum in any script that saves files, as it is common to strip the filename extension from the current format to replace it with another one when saving in a different format.

 

The most flexible and elegant method is via a regular expression find/replace (works with single or multiple period characters):

 

var dName = activeDocument.name.replace(/\.[^\.]+$/, '');
alert(dName);

 

Another simpler method is via a split/remove on th

...

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 06, 2024 Jan 06, 2024

Copy link to clipboard

Copied

LATEST

@Ciccillotto 

 

You should be able to find examples of this on the forum in any script that saves files, as it is common to strip the filename extension from the current format to replace it with another one when saving in a different format.

 

The most flexible and elegant method is via a regular expression find/replace (works with single or multiple period characters):

 

var dName = activeDocument.name.replace(/\.[^\.]+$/, '');
alert(dName);

 

Another simpler method is via a split/remove on the period character, retaining the characters on the left (presuming a "clean" filename with only a single period character):

 

var dName = activeDocument.name.split('.')[0];
alert(dName);

 

If there are multiple period characters in the filename, presume that the last period is the extension:

 

var extensionIndex = activeDocument.name.lastIndexOf(".");
if (extensionIndex != -1) {
    var dName = activeDocument.name.substr(0, extensionIndex);
    alert(dName);
} else {
    alert(activeDocument.name);
}

 

https://gist.github.com/MarshySwamp/40aefebb39e0eef2d7599ac4050490d9

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines