⎕WSIDreturns a blank result whene executed under the standalone .exe's runtime.
Best way to determine ws dir while running standalone .exe
- norbertjurkiewicz84
- Posts: 62
- Joined: Mon Nov 01, 2010 7:26 pm
Best way to determine ws dir while running standalone .exe
What is the best way to get the parent directory of the application.
(It's the little things that make the difference :-)
Re: Best way to determine ws dir while running standalone .e
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)
To get the current directory you just call CD with an empty argument:
Cheers
Gil
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
Donno if this will help but you can also get the command line by doing
+2⎕nq'.' 'getcommandline'
/Dan
+2⎕nq'.' 'getcommandline'
/Dan
-
- Posts: 439
- Joined: Wed Oct 01, 2008 9:39 am
Re: Best way to determine ws dir while running standalone .e
Also, if the location of the standalone .exe is something that you can use to determine the ws dir, you could do this:
Regards,
Vince
'gmf'⎕NA'U4 kernel32|GetModuleFileName* U4 >0T U4'
text2←2⊃gmf 0 255 255
Regards,
Vince
- norbertjurkiewicz84
- Posts: 62
- Joined: Mon Nov 01, 2010 7:26 pm
Re: Best way to determine ws dir while running standalone .e
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 :-)
- Morten|Dyalog
- Posts: 460
- Joined: Tue Sep 09, 2008 3:52 pm
Re: Best way to determine ws dir while running standalone .e
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
The user command CD, like most user commands can be called under program control by doing
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.
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.