Skip to main content
K.Daube
Community Expert
Community Expert
June 19, 2021
Answered

How to create a folder?

  • June 19, 2021
  • 1 reply
  • 464 views

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 has been closed for replies.
Correct answer Klaus Göbel

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

 

1 reply

Klaus Göbel
Klaus GöbelCorrect answer
Legend
June 19, 2021

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

 

K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
June 19, 2021

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.
};

 

frameexpert
Community Expert
Community Expert
June 19, 2021

Hi Klaus,

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

Rick