Skip to main content
Inspiring
May 17, 2022
Question

Create folder in root directory using extendscript

  • May 17, 2022
  • 2 replies
  • 1761 views

Hi All,

 

I am able to create the folder in desktop.

var f = new Folder("~/Desktop/new_fodler");  
f.create();

 

But I couldn't create the folder in /Users/ directory.

var f = new Folder("/Users/new_fodler");
f.create();

 

Could anyone help me on troubleshooting this. Is this required any permissions with the code?

 

Thanks. 

This topic has been closed for replies.

2 replies

Community Expert
May 17, 2022

Hi together,

currently I cannot test this on MacOS, but I remember that there was a discussion ten years ago:

https://community.adobe.com/t5/indesign-discussions/extendscript-oddity-with-file-folder-on-mac-os-x/m-p/3887833#M165122

 

I'm quoting Joris_Coppieters from that discussion:

 

// BEGIN QUOTE:

 

I can successfully reference a folder object on my desktop using the hack function:

var folder = Folder(newFile("~/Desktop/Test"));

 

But if you still have a Users folder in your Volumes, calling:

folder.create();

Will return true but won't create the folder on the desktop.

 

Where was it created?

In the /Volumes/Users directory!

=> /Volumes/Users/[USERNAME]/Desktop/Test

 

// END QUOTE

 

 

Don't know if this is still relevant…

Well, could be.

 

Joris presented the following solution in 2012:

https://community.adobe.com/t5/indesign-discussions/extendscript-oddity-with-file-folder-on-mac-os-x/m-p/3887837#M165126

 

Others commented as well eight years later in 2020 with different ideas to solve the issue.

O2-Creative:

https://community.adobe.com/t5/indesign-discussions/extendscript-oddity-with-file-folder-on-mac-os-x/m-p/10925859#M175575

 

Dirk Becker:

https://community.adobe.com/t5/indesign-discussions/extendscript-oddity-with-file-folder-on-mac-os-x/m-p/11207648#M190211

 

 

Regards,
Uwe Laubender
( Adobe Community Professional )

rob day
Community Expert
Community Expert
May 17, 2022

Hi @AD4003 , the parent of the desktop should be the user folder, so try this:

 

var f = new Folder(Folder.desktop.parent + "/new_folder")
f.create();

 

AD4003Author
Inspiring
May 17, 2022

Hi rob day

Thanks for your reply. But, I want to create a folder under "/Users" directory not in "/Users/<username>".

rob day
Community Expert
Community Expert
May 17, 2022

I can make a folder in the System/Users directory on OSX Mojave by adding a parent, but I have to give the Users folder Read/Write permissions or the folder will not be created

 

//create a new folder in the System/Users folder
var f = new Folder(Folder.desktop.parent.parent + "/new_folder")
f.create();

 

 

 

Also here is the Folder API page which includes shortcuts to common folders—you can back out of these folders using .parent, but you do need permission:

 

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Folder.html

 

 

Some examples:

 

$.writeln("User Desktop: " + Folder.desktop)
//~/Desktop

$.writeln("System Application Support Folder: " + Folder.appData.fsName)
//System Application Folder: /Library/Application Support

$.writeln("User Application Support Folder: " + Folder.userData.fsName)
//User Application Support Folder: ~/Library/Application Support

$.writeln("Target Application Folder: " + Folder.appPackage.fsName)
//Applications/Adobe InDesign 2020/Adobe%20InDesign 2020.app

$.writeln("Documents Folder: " + Folder.myDocuments)
//Documents Folder: ~/Documents

$.writeln("Application Startup Folder: " + Folder.startup.fsName)
//Application Startup Folder: /Applications/Adobe InDesign 2020/Adobe InDesign 2020.app/Contents/MacOS

$.writeln("System Folder: " + Folder.system)
//System Folder: /System

$.writeln("Temp Folder: " + Folder.temp)
//Temp Folder: /private/var/folders/w2/s1lk7d6d3m95v4pq7m4flscw0000gn/T/TemporaryItems

$.writeln("Trash Folder: " + Folder.trash)
//Trash Folder: ~/.Trash


var dt = Folder.desktop
$.writeln("Full Destop Path: " + dt.relativeURI)
//Full Destop Path: /Users/fishercat/Desktop

var uas = Folder.userData
$.writeln("Full Destop Path: " + uas.parent)

var CC = File(Folder.desktop.parent.parent + "/Creative Cloud Files")
$.writeln("CCF Folder: " + CC);