Author Topic: How to get or set current working directory?  (Read 5810 times)

xtradev

  • Newbie
  • *
  • Posts: 9
    • View Profile
How to get or set current working directory?
« on: May 19, 2015, 02:58:21 am »
For example, I want to execute system() function that will call a program that writes text file that I intend to read back into esProc. I want this text file to be written alongside the esProc worksheet file that I am running.

How to construct a file path without hard-coding it? Is there a command to get or set current working directory?

Without specifying a file path the file goes into C:\Programs\raqsoft\esProc\bin.

todaydad

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: How to get or set current working directory?
« Reply #1 on: May 19, 2015, 07:24:30 am »
An option is to direct double-click the dfx file to launch IDE. In this case the current path is the directory where the dfx file resides.

I’ve tried this method. It goes like this:

1.   Write a file - getdir.cmd - for batch processing and put it in the root directory on drive D. There is only the command "dir >d:\result.txt" in the file.

2.   Write the esProc code – A2=system("cmd /C d:\\getdir.cmd") – and save it as test.dfx.

3.   Double click test.dfx to launch IDE and execute the script. By doing so, the current path displayed in result.txt is the one where test.dfx resides.

Another choice is to use esProc function invoke to call JAVA static method. I failed to make it work. But you can have a try.

This is what I did: wrote an esProc script -  A1=invoke(java.lang.System.setProperty,"user.dir","c:\\") - to call java.lang.System’s setProperty function, and executed A3=invoke(java.lang.System.getProperty,"user.dir") and I could see the modification is done. Then I executed A2 but found that nothing changed in result.txt.
The reason is that user.dir is not passed to function system, We are doing a research on it, so you can wait some days.

todaydad

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: How to get or set current working directory?
« Reply #2 on: May 19, 2015, 03:00:13 pm »
As a temporary solution,you can use "filename@d(directory@p("")(1))" to get main path, It is the same as dfx file path if  you don't make any chaange at path config.
Yes, we still try to get a more convenient solution.

xtradev

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: How to get or set current working directory?
« Reply #3 on: May 21, 2015, 11:54:37 pm »
filename@d(directory@p("")(1)) is a good solution. Thank you.

I have tried to java.lang.System.setProperty. And yes, getProperty sees it has been set, but system() does not.

Double-clicking dfx file does also work and is a viable option.

Thank you.
« Last Edit: May 23, 2015, 07:28:36 am by xtradev »

todaydad

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: How to get or set current working directory?
« Reply #4 on: May 22, 2015, 12:57:28 am »
As to now, We can't passed user.dir to function system( sub thread),  so we decided to add a option to function filename  to get main path ,

You can wait for this new feature at next version,usually 1-2 weeks ;-)