Author Topic: Get directory from JScript script  (Read 1747 times)

M1TO

  • EA User
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Get directory from JScript script
« on: December 13, 2022, 09:21:43 pm »
Hi.

I know how to get a file name including the path with Repository.GetProjectInterface().GetFileNameDialog(). But is there a way select a folder instead of a file as input for the script?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13404
  • Karma: +567/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Get directory from JScript script
« Reply #1 on: December 13, 2022, 09:29:39 pm »
I do this in my FileSystemFolder class in VBScript: https://github.com/GeertBellekens/Enterprise-Architect-VBScript-Library/blob/master/Framework/Utils/FileSystemFolder.vbs

I'm sure you can do something similar in jscript

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

Geert

M1TO

  • EA User
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: Get directory from JScript script
« Reply #2 on: December 14, 2022, 12:52:40 am »
Thanks a lot Geert for the quick response. BrowseForFolder was exactly what I was looking for!