Skip to main content
Inspiring
March 23, 2018
Answered

Save an open file to another folder

  • March 23, 2018
  • 1 reply
  • 658 views

Hallo.

My intension is to open a document and save it at an other place (by choosing the path).

var myPath = new File (path);

var openFile = myPath.openDlg("Wähle die Datei aus");

       

var myNewBook = app.open(File(openFile));

var sv = File(myNewBook.name).saveDlg("Bitte Dokumentennamen eingeben.", ".indb");

if (sv != 0){

   var doc = myNewBook.save(File(sv.path));

   

    }

myNewBook.close(SaveOptions.YES);

This works until line 6. Then comes an error message like "you cannot save the dokument, it´s allready open".

A second question: where can I set a default saving-path (line 6)?

Greets!

This topic has been closed for replies.
Correct answer cmoke73

Hi Peter.

Only five minutes ago I found the following solution:

var myPath = new File ("/path");

var openFile = myPath.openDlg("Wähle die Datei aus");

var myNewBook = app.open(File(openFile));

var sv = File(myNewBook.name.replace(myNewBook.name, newBookName)).saveDlg("Bitte Speicherort auswählen: " + newBookName,"INDB files: *.indb");

myNewBook.save(File(sv.fullName));

Thank you for your solution. Of course I´ll try that too.

Andreas

1 reply

Peter Kahrel
Community Expert
Community Expert
March 26, 2018

Instead of

var doc = myNewBook.save(File(sv));

use this:

var doc = myNewBook.save (sv);

saveDlg() returns a file object, and you should save a document using a full path name.

Another thing: you use this:

var sv = File(myNewBook.name).saveDlg(...)

and because you don't have a path name there, just a file name, saveDlg() targets the desktop by default. If that's what you want, fine. But otherwise use this:

var sv = File(myNewBook.fullName).saveDlg(...)

which is usually closer to where you want to go.

> where can I set a default saving-path (line 6)?

var sv = Folder('/d/test/').saveDlg("Bitte Dokumentennamen eingeben.", ".indb");

Peter

cmoke73AuthorCorrect answer
Inspiring
March 26, 2018

Hi Peter.

Only five minutes ago I found the following solution:

var myPath = new File ("/path");

var openFile = myPath.openDlg("Wähle die Datei aus");

var myNewBook = app.open(File(openFile));

var sv = File(myNewBook.name.replace(myNewBook.name, newBookName)).saveDlg("Bitte Speicherort auswählen: " + newBookName,"INDB files: *.indb");

myNewBook.save(File(sv.fullName));

Thank you for your solution. Of course I´ll try that too.

Andreas