Skip to main content
Inspiring
June 30, 2016
Question

Unable to create Folder -object in JS - only works in JSX

  • June 30, 2016
  • 1 reply
  • 1416 views

I'm making a Photoshop panel and I have a drop-down menu that I want to populate with elements based on the number of files in a folder. However, for reasons unknown to me I seem to be completely unable to create Folder-objects in the javascript file. I've tested the below three lines of code both in my JSX file and my JS file. In the JSX one it works as it should: I get an alert dialog printing out the temp/dummy name of the folder. In JS though the entire script comes to a halt after the row creating the folder. Why is this?

alert("trying to make folder...");

var lol = new Folder();

alert(lol);

This topic has been closed for replies.

1 reply

Pedro Cortez Marques
Legend
June 30, 2016

var FF=  Folder(Folder.desktop + "/myFolder");

if (!FF.exists) FF.create();

HeimdaalAuthor
Inspiring
June 30, 2016

Specifying a path changes nothing for me - the object is still not created, instead the code comes to a halt before the second alert. Also doing theFolder.create() does nothing either

EDIT: I even tried hardcoding the folder path and also make sure that the folder didn't exist already, but for reasons unknown the Folder-object is still not created.

fontAbsPath = "c:/Users/martin.dahlin/Desktop/Test/";

alert("trying to make folder... fontAbsPath is:\n" + fontAbsPath); // This is correct

var fontFolder = new Folder(fontAbsPath); // Script HALTS here! :(

if(!fontFolder.exists){

    alert("created folder because it didn't exist");

    fontFolder.create();

}else{

    alert("didn't create the folder because it already exists!");

}

HeimdaalAuthor
Inspiring
July 1, 2016

The best person to help you may be id Davide Barranca:

Photoshop, etc. | Random thoughts on Photoshop, Coding and all the rest


I figured it out.
The File and Folder -objects are an ExtendScript -thing. They don't exist in JavaScript (at least I don't think so - as you cannot even create new empty Folder objects!)