Page 1 of 1

Best way to determine ws dir while running standalone .exe

Posted: Mon Sep 17, 2012 5:47 pm
by norbertjurkiewicz84
What is the best way to get the parent directory of the application.
      ⎕WSID
returns a blank result whene executed under the standalone .exe's runtime.

Re: Best way to determine ws dir while running standalone .e

Posted: Tue Sep 18, 2012 7:51 am
by gil
Hi Norbert

If running under Windows, you can get the current directory using the Windows API. On the APL wiki you can find a collection of tools under the APLTree project. One of them is WinFile and that one contains most of the methods you'd need for accessing the file system. You can find it under:

http://aplwiki.com/WinFile

If you don't think you'll need all that, the user command ]CD will give you what you need. I don't know that you can call a user command in execution mode, but the code is available in the script \Dyalog APL-64 13.1 Unicode\SALT\Spice\Summary.dyalog (extract below)

Code: Select all

    ∇ {old}←CD new;get;set;size;t                         ⍝ Change directory.
     ⍝ Change Directory under DOS
      t←'A*'[1+80=⎕DR'']
      'get'⎕NA'U Kernel32|GetCurrentDirectory',t,' U >0T' ⍝ Associate Get function.
      'set'⎕NA'U Kernel32|SetCurrentDirectory',t,' <0T'   ⍝     "     Set    "
      (size old)←get 260 260                              ⍝ Get current directory.
      :If ×⍴,new                                          ⍝ If target directory.
          ⎕SIGNAL(set⊂new)↓11                             ⍝ Domain error if fails.
      :End                                                ⍝ Old dir is shy rslt.
    ∇


To get the current directory you just call CD with an empty argument:

Code: Select all

parentDirectory←CD''


Cheers

Gil

Re: Best way to determine ws dir while running standalone .e

Posted: Tue Sep 18, 2012 8:17 am
by DanB|Dyalog
Donno if this will help but you can also get the command line by doing

+2⎕nq'.' 'getcommandline'

/Dan

Re: Best way to determine ws dir while running standalone .e

Posted: Tue Sep 18, 2012 11:51 am
by Vince|Dyalog
Also, if the location of the standalone .exe is something that you can use to determine the ws dir, you could do this:

      'gmf'⎕NA'U4 kernel32|GetModuleFileName* U4 >0T U4'
text2←2⊃gmf 0 255 255


Regards,

Vince

Re: Best way to determine ws dir while running standalone .e

Posted: Fri Sep 28, 2012 5:01 pm
by norbertjurkiewicz84
DanB|Dyalog wrote:Donno if this will help but you can also get the command line by doing

+2⎕nq'.' 'getcommandline'

/Dan

I though this would be nice but it doesn't work well in dev. mode. You get the path of the interpreter not the current location of the WS.

Vince|Dyalog wrote:Also, if the location of the standalone .exe is something that you can use to determine the ws dir, you could do this:

      'gmf'⎕NA'U4 kernel32|GetModuleFileName* U4 >0T U4'
text2←2⊃gmf 0 255 255


Regards,

Vince

Same thing, I get the parent .exe not the WS path. :-(

And the winner is....
gil wrote:Hi Norbert

If running under Windows, you can get the current directory using the Windows API. On the APL wiki you can find a collection of tools under the APLTree project. One of them is WinFile and that one contains most of the methods you'd need for accessing the file system. You can find it under:

http://aplwiki.com/WinFile

If you don't think you'll need all that, the user command ]CD will give you what you need. I don't know that you can call a user command in execution mode, but the code is available in the script \Dyalog APL-64 13.1 Unicode\SALT\Spice\Summary.dyalog (extract below)

Code: Select all

    ∇ {old}←CD new;get;set;size;t                         ⍝ Change directory.
     ⍝ Change Directory under DOS
      t←'A*'[1+80=⎕DR'']
      'get'⎕NA'U Kernel32|GetCurrentDirectory',t,' U >0T' ⍝ Associate Get function.
      'set'⎕NA'U Kernel32|SetCurrentDirectory',t,' <0T'   ⍝     "     Set    "
      (size old)←get 260 260                              ⍝ Get current directory.
      :If ×⍴,new                                          ⍝ If target directory.
          ⎕SIGNAL(set⊂new)↓11                             ⍝ Domain error if fails.
      :End                                                ⍝ Old dir is shy rslt.
    ∇


To get the current directory you just call CD with an empty argument:

Code: Select all

parentDirectory←CD''


Cheers

Gil


This call gives me the directory that has the workspace. It work for both dev. and in a standalone .exe.

Thank you all for the suggestions.
Norbert.

Re: Best way to determine ws dir while running standalone .e

Posted: Sat Sep 29, 2012 8:01 am
by Morten|Dyalog
Functions to get and set the current directory can also be found in the distributed workspace "files":

      )load files
C:\Program Files\Dyalog\Dyalog APL-64 13.1 Unicode\ws\files saved Tue May 22 17:11:40 2012
Files.GetCurrentDirectory
c:\progra~1\micros~2\office14
Files.SetCurrentDirectory 'c:\temp'
Files.GetCurrentDirectory
c:\temp

Re: Best way to determine ws dir while running standalone .e

Posted: Sat Sep 29, 2012 11:45 am
by DanB|Dyalog
The user command CD, like most user commands can be called under program control by doing

Code: Select all

var<-[]SE.UCMD 'CD'

User commands should always return a result, even if empty.

But CD (like other solutions proposed here) won't tell you the folder of your workspace directory, it will only tell you your CURRENT working directory.
This is different. Your ws may have come from a different location.

The commandline technique has the benefit of showing where your original ws came from. If it is a relative path it can be guessed by using the program's path but this is not foolproof has you may have started in a different folder.