Author Topic: How to get the user to select a folder from a JS script (EA14)  (Read 1901 times)

yonatan.lehman

  • EA User
  • **
  • Posts: 47
  • Karma: +0/-0
    • View Profile
Hi
I can ask the user to select a file using Repository.InvokeFileDialog  or use DLGOpenFile from EAScriptLBi.JScript-Dialog.

How do I open a dialog that allows the user to select (or create) a directory (folder)?
I know almost nothing about VB - so a good example in JS, or can be converted to JS would be great!

Thanks

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to get the user to select a folder from a JS script (EA14)
« Reply #1 on: June 27, 2022, 11:20:44 pm »
I only use VBScript, so this is what I use in a class called FileSystemFolder: https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/master/Framework/Utils/FileSystemFolder.vbs

Code: [Select]
'let the user select a folder, optionally from a given starting path.
public function getUserSelectedFolder(startPath)
dim folder, shell
Set shell  = CreateObject( "Shell.Application" )
if len(startPath) > 0 then
Set folder = shell.BrowseForFolder( 0, "Select Folder", 0,startPath)
else
Set folder = shell.BrowseForFolder( 0, "Select Folder", 0)
end if
if not folder is nothing then
set getUserSelectedFolder = New FileSystemFolder
getUserSelectedFolder.FullPath = folder.Self.Path
Session.Output "folder.Self.Path: " & folder.Self.Path
else
set getUserSelectedFolder = Nothing
end if
end function


I hope this helps. I guess you should be able to translate that to JS pretty easily.

Geert

yonatan.lehman

  • EA User
  • **
  • Posts: 47
  • Karma: +0/-0
    • View Profile
Re: How to get the user to select a folder from a JS script (EA14)
« Reply #2 on: June 28, 2022, 12:30:48 am »
Cheers !

yonatan.lehman

  • EA User
  • **
  • Posts: 47
  • Karma: +0/-0
    • View Profile
Re: How to get the user to select a folder from a JS script (EA14)
« Reply #3 on: June 28, 2022, 12:42:41 am »
Based on JScript-Dialog
the VB equivilent of
   set openFileDialog = CreateObject("MSComDlg.CommonDialog")
is
  var openFileDialog = new ActiveXObject("MSComDlg.CommonDialog");

But when I do this (as a 1st step before trying to change it to "Shell.Application")
I get an Error Dialog:

Automation server can't create object


I guess I need to set some permission - but how ?