Skip to main content
Stefan Riedmann
Inspiring
November 27, 2018
Answered

SaveAs under Windows errs with 'The file may be read-only'

  • November 27, 2018
  • 1 reply
  • 847 views

1. I have a new (untitled) document

2. My scripts tries to perform 'SaveAs(filepath)'

3. A error popup appears "The file may be raed-only, or another user may have it open. Please save the document with a different name or in a different folder."

When I use the EXACT SAME filepath, and go manually to the menu - SaveAs, and paste the file path there, it works perfectly.

I'm 100% sure that the given filepath does not exist before the script runs.

We can't back-check right now, but the same script worked fine in Illustrator CC 2018, is that possible?

Again, it just happens on Windows!

Best regards,

Stefan

This topic has been closed for replies.
Correct answer Disposition_Dev

the saveAs command requires a File() object, not just a path. You should be able to use backslashes as well as long as they are escaped properly (which it looks like they are based on your regex).

try this:

var filePath = "path\\to\\save\\destination\\fileName.ai";

var saveFile = File(filePath);

app.activeDocument.saveAs(saveFile);

1 reply

CarlosCanto
Community Expert
Community Expert
November 28, 2018

please post your code to see if we spot the issue

Stefan Riedmann
Inspiring
December 3, 2018

Hi!

We could solve it finally. The weird thing is that the 'SaveAs' operation needs a unix filepath as destination, which now we generate like this on Windows:

destinationPath = destinationPath.replace(/\\/g,'/');

For a normal 'Save' operation, or for a SaveAs with PDF options (for export), this is not necessary. AND this appeared with Illustrator 2019, because I'm sure that our former implementation was working fine with Illustrator 2018 on Windows.

Best regards,

Stefan

Disposition_Dev
Disposition_DevCorrect answer
Legend
December 3, 2018

the saveAs command requires a File() object, not just a path. You should be able to use backslashes as well as long as they are escaped properly (which it looks like they are based on your regex).

try this:

var filePath = "path\\to\\save\\destination\\fileName.ai";

var saveFile = File(filePath);

app.activeDocument.saveAs(saveFile);