Skip to main content
K.Daube
Community Expert
Community Expert
Jun 19, 2021 8:14 AM UTC
Answered

How to create a folder?

Coming along a problem I wrote this simple test:

#target framemaker
var backupFolder;
  backupFolder = new Folder ("E:\\_DDDprojects\\FM-JsxLib\\Docu" + "\\_Backups1");
  backupFolder = new Folder ("/e/DDDprojects/FM-JsxLib/Docu" + "/_Backups2");

Running in ESTK with an FM document open:

Selected target is ESTK CC :

   Result: /e/DDDprojects/FM-JsxLib/Docu/_Backups1
   Result: /e/DDDprojects/FM-JsxLib/Docu/_Backups2

Selected target is FrameMaker 15

   Result: /e/DDDprojects/FM-JsxLib/Docu/_Backups2

In both scenarios no folder is created!

I do not get an error from the New command (backupFolder.error is a blank string)

This topic is closed to new replies. Start a new post to keep the conversation going.
Klaus Göbel
Klaus GöbelCorrect answer
Legend
Jun 19, 2021 8:17 AM UTC

Hi Klaus,

you have only created a Folder object, but not a folder.

To create the folder:

if (!backupFolder.exists){backupFolder.create()}

Have a nice day

 

3 replies

Klaus Göbel
Klaus GöbelCorrect answer
Legend
Jun 19, 2021 8:17 AM UTC

Hi Klaus,

you have only created a Folder object, but not a folder.

To create the folder:

if (!backupFolder.exists){backupFolder.create()}

Have a nice day

 

Translate
K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
Jun 19, 2021 12:07 PM UTC

Thanks, Klaus, for this enlightment!

But, why does Rick's code (part of the event script here only) work?

CP_BA.backupOnSave = function (sparam) {	
  var backupFolder, file;
  backupFolder = new Folder ("C:\\DATA\\Scripts\\_Backups"); // Target folder for backups.
  file = new File (sparam);                     // Make a file object for the document that was just saved.
  file.copy (new File (backupFolder + "\\" + file.name)); // Copy the file to the backup folder.
};

 

Translate
frameexpert
Community Expert
Community Expert
Jun 19, 2021 12:15 PM UTC

Hi Klaus,

I will have to look at my code, but I may have made the assumption that the folder already exists.

Rick

Translate
www.frameexpert.com