Highlighted

exportFile eliminating . and everything after it in file name?

Participant ,
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

92

Likes

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

exportFile eliminating . and everything after it in file name?

Participant ,
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

93

Likes

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
Nov 15, 2020 0
Most Valuable Participant ,
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!"

Likes

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
Reply
Loading...
Nov 15, 2020 0
Participant ,
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!  😉

Likes

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
Reply
Loading...
Nov 15, 2020 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Nov 15, 2020 0
Participant ,
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.

Likes

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
Reply
Loading...
Nov 15, 2020 0
Most Valuable Participant ,
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.

Likes

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
Reply
Loading...
Nov 15, 2020 0
Participant ,
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.

Likes

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
Reply
Loading...
Nov 15, 2020 0
Most Valuable Participant ,
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.)

Likes

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
Reply
Loading...
Nov 15, 2020 0
Participant ,
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");

 

 

Likes

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
Reply
Loading...
Nov 15, 2020 0
Most Valuable Participant ,
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");

Likes

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
Reply
Loading...
Nov 15, 2020 0
Participant ,
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.

Likes

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
Reply
Loading...
Nov 15, 2020 0
Resources