Best way to determine ws dir while running standalone .exe

General APL language issues

Best way to determine ws dir while running standalone .exe

Postby norbertjurkiewicz84 on Mon Sep 17, 2012 5:47 pm

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.
(It's the little things that make the difference :-)
User avatar
norbertjurkiewicz84
 
Posts: 62
Joined: Mon Nov 01, 2010 7:26 pm

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

Postby gil on Tue Sep 18, 2012 7:51 am

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
gil
 
Posts: 71
Joined: Mon Feb 15, 2010 12:42 am

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

Postby DanB|Dyalog on Tue Sep 18, 2012 8:17 am

Donno if this will help but you can also get the command line by doing

+2⎕nq'.' 'getcommandline'

/Dan
DanB|Dyalog
 

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

Postby Vince|Dyalog on Tue Sep 18, 2012 11:51 am

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
Vince|Dyalog
 
Posts: 413
Joined: Wed Oct 01, 2008 9:39 am

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

Postby norbertjurkiewicz84 on Fri Sep 28, 2012 5:01 pm

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.
(It's the little things that make the difference :-)
User avatar
norbertjurkiewicz84
 
Posts: 62
Joined: Mon Nov 01, 2010 7:26 pm

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

Postby Morten|Dyalog on Sat Sep 29, 2012 8:01 am

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
User avatar
Morten|Dyalog
 
Posts: 453
Joined: Tue Sep 09, 2008 3:52 pm

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

Postby DanB|Dyalog on Sat Sep 29, 2012 11:45 am

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.
DanB|Dyalog
 


Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest