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

exportFile eliminating . and everything after it in file name?

Engaged ,
Nov 15, 2020 Nov 15, 2020

Copy link to clipboard

Copied

Hi,

I am observing that when exporting a file to PNG with the exportFile method in JavaScript, if the fileSpec name contains a ".", then the resulting filename eliminates the dot and anything that is after it.

Is this a bug? Is there a way around it?

So a filename like illustrator2.3 would be saved as illustrator2.png instead of illustrator2.3.png

This is for CS4.

Thanks.

TOPICS
Scripting

Views

352

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 , Nov 15, 2020 Nov 15, 2020

It seems like it is.

I have never encountered problems like this because I have always done error management on my script files and always cleaning up the filenames and adding the correct extension before saving or exporting them.

 

 

Sure you can use:

exportFileToPNG8("D:/destinationfolder/file_without_periods-in-name.ai");

and you will receive an exported file_without_periods-in-name.png

 

I do not work like that.

AND You wouldn't have the problem if you didn't use periods in the filename.

Votes

Translate

Translate
Adobe
Community Expert ,
Nov 15, 2020 Nov 15, 2020

Copy link to clipboard

Copied

Please show your script.

There are several techniques for creating the filename without an extension.

For example

indexOf()

or regex like

/\..+$/

Which one do you use?

 

Both variants will fails with a dot in the file name.

My motto is: "Never use a period in the file name - never!"

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
Engaged ,
Nov 15, 2020 Nov 15, 2020

Copy link to clipboard

Copied

Hi pixxxelschubser. Thanks for your reply. I am not sure I am understanding what you are saying. Let me give you more information in case I wasn't clear. I am referring to the exportFile method used in Illustrator scripting. That method is described as automatically removing the file extension, if any is included.

Take a look at this file, the example on page 59. The method exportFile is described on page 40.

https://www.adobe.com/content/dam/acom/en/devnet/illustrator/pdf/Illustrator_Scriptin_Reference_Java...

 

exportFile seems to be non-discerning and systematically removes the last "." in the filename, and anything that follows it.

 

I don't disagree with your motto but when it's there, it's there!  😉

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
Community Expert ,
Nov 15, 2020 Nov 15, 2020

Copy link to clipboard

Copied

Sorry.

Many things have changed since the 8.3 file naming convention. The "period" as a separator has remained. The "period" is a "reserved character" - the separator between file name and extension and should never be part of the file name. There is nothing more to say.

 

I know the script reference. Please show us a working script example in which "everything from point" is automatically removed.

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
Engaged ,
Nov 15, 2020 Nov 15, 2020

Copy link to clipboard

Copied

In my case, the period was also part of the filename, which was provided to exportFile without the file extension. Given that exportFile seems to look for a period in the filename, it removed everything after that in the resulting file. I am pretty sure that if in the example of page 59, dest is provided as, say dest = "D:/path/file.name.22", then the actual file name will be "file.name.png" instead of "file.name.22.png".

 

 

 

function exportFileToPNG8 (dest) {
if ( app.documents.length > 0 ) {
var exportOptions = new ExportOptionsPNG8();
var type = ExportType.PNG8;
var fileSpec = new File(dest);
exportOptions.colorCount = 8;
exportOptions.transparency = false;
app.activeDocument.exportFile( fileSpec, type, exportOptions );}
}

 

 

 

A quick workaround I can think of is to add a ".decoy" at the end of the file name so exportFile thinks that is the extension it must remove and spares any other period in the filename. So, in my example, I would provide dest = "D:/path/file.name.22.decoy" to get "file.name.22.png" in the end. I noticed that any number of successive dots would be removed (like "....decoy").

 

If that is indeed how this works, then perhaps the description of exportFile in the pdf is a little misleading or could be completed.

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
Community Expert ,
Nov 15, 2020 Nov 15, 2020

Copy link to clipboard

Copied

Sorry again.

You only shows the function for export from the documentation. Missing the call of the function - and more important: what you have set for "dest".

 

Can't help you without this (complete) information.

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
Engaged ,
Nov 15, 2020 Nov 15, 2020

Copy link to clipboard

Copied

I provided the function script on page 59 of the Adobe PDF document. I explained what I would set for "dest" in the example and how the expected and likely outcomes would differ.

Unfortunately, I can't provide the script I am working on here.

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
Community Expert ,
Nov 15, 2020 Nov 15, 2020

Copy link to clipboard

Copied

I only need the part that processes the file name and stores it as the variable "dest".

 

As I have already written: Only there the error can be localized. (And of course with the problematic use of the "period" in the file name.)

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
Engaged ,
Nov 15, 2020 Nov 15, 2020

Copy link to clipboard

Copied

You can try this complete code, which uses the function from page 59. You will see that the file name it saves to is "file.name.22.png" instead of "file.name.22.decoy.png". An AI document must be open prior to running it.

 

 

 

function exportFileToPNG8 (dest) {
	if ( app.documents.length > 0 ) {
		var exportOptions = new ExportOptionsPNG8();
		var type = ExportType.PNG8;
		var fileSpec = new File(dest);
		exportOptions.colorCount = 8;
		exportOptions.transparency = false;
		app.activeDocument.exportFile( fileSpec, type, exportOptions );
		}
}

exportFileToPNG8("D:/destinationfolder/file.name.22.decoy");

 

 

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
Community Expert ,
Nov 15, 2020 Nov 15, 2020

Copy link to clipboard

Copied

If you really want to use periods in a filename:

I wonder - why not easy use a complete file name for export:

exportFileToPNG8("D:/destinationfolder/file.name.22.decoy.png");

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
Engaged ,
Nov 15, 2020 Nov 15, 2020

Copy link to clipboard

Copied

Yes, that is a solution too, pixxxelschubser. ".decoy" was added to be removed by exportFile so it was not meant to be in the resulting file.

exportFileToPNG8("D:/destinationfolder/file.name.22.png")

The thing is that my understanding of the description for exportFile was that it would automatically add the file extension, in this case ".png", to the file name. What I didn't know is that it would also automatically remove any existing file extension in the file name or anything it interpreted as a file extension. It took some searching to figure out where the problem was coming from.

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
Community Expert ,
Nov 15, 2020 Nov 15, 2020

Copy link to clipboard

Copied

It seems like it is.

I have never encountered problems like this because I have always done error management on my script files and always cleaning up the filenames and adding the correct extension before saving or exporting them.

 

 

Sure you can use:

exportFileToPNG8("D:/destinationfolder/file_without_periods-in-name.ai");

and you will receive an exported file_without_periods-in-name.png

 

I do not work like that.

AND You wouldn't have the problem if you didn't use periods in the filename.

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
Engaged ,
Nov 15, 2020 Nov 15, 2020

Copy link to clipboard

Copied

I was providing a file name without an extension to exportFile, since exportFile would be adding it anyway. Had I added the extension to the file name, I would not have observed this problem! So here I should add to your motto, to make it mine: "try not to be clever". 😄

Again, I agree (to some extent) with no periods in file names, but when they are named with periods already, what can you do? I tried to deal with them rather than renaming them.

Thanks for spending time to look into this problem with me.

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
Community Expert ,
Nov 15, 2020 Nov 15, 2020

Copy link to clipboard

Copied

LATEST

😄

An ancient wisdom:
Scripts are as smart as you program them.
Scripts are as stupid as you program them to be.

 

😉

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