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

Save an open file to another folder

Engaged ,
Mar 23, 2018 Mar 23, 2018

Copy link to clipboard

Copied

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!

TOPICS
Scripting

Views

570

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

Engaged , Mar 26, 2018 Mar 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

Votes

Translate

Translate
Community Expert ,
Mar 26, 2018 Mar 26, 2018

Copy link to clipboard

Copied

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

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 ,
Mar 26, 2018 Mar 26, 2018

Copy link to clipboard

Copied

LATEST

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

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