Hi Bert,
thank you for this.
You could submit this as an RFE at sourceforge, however I wonder how likely
it is to be picked up. I know that at least three people misunderstood the
ambiguous phrase in the helpfile (you, me and whoever 'improved' the
helpfile away from the less ambiguous previous wording) but my guessis that
the majority of users never had a problem with this.
I think Chip is right, the directory function tries to do too many things
for a function that returns one datum. Whilst returning the old current
directory feels intuitive in one sense, it doesn't take into account the
possibility that the operation might fail. Indeed, Personal Rexx provided
two functions, one to identify the current directory and another to change
it, which returned a success or failure indication.
If we were to go ahead and do this enhancement, then you would need to
change your code wherever you used the directory bif anyway, and even
though you might feel this would streamline code, one might have to add
lines to cope with error conditions so one can't have a streamlined push
and pop of directory in two lines anyway.
Perhaps what you want is a wrapper like the below which would allow you to
pop and push directories with a single line and trap any errors using signal
> *::routine directory2 public*
> *pwd = directory()*
> *call directory arg(1)*
> *if result = ''*
> *then raise syntax 48.900 array('Could not change directory to' target)**else
> RETURN pwd*
you could then use it like this
>
>
>
> *pwd = directory2()/* commands that need a different directory*/call
> directory2 pwd*
Instituting your own error handler or using the default one
here is a little code demonstrating it
>
>
>
>
>
> *trace asay directory()pwd = directory2('c:\') -- this one existssay
> 'pwd='pwd', directory='directory()pwd = directory2('c:\unknown') -- this
> one does not existsay 'pwd='pwd', directory='directory()*
and here is the output
>
> *C:\oorexx>rexx test*
> * 2 *-* say directory()*
> *C:\oorexx*
> * 3 *-* pwd = directory2('c:\') -- this one exists*
> * 4 *-* say 'pwd='pwd', directory='directory()*
> *pwd=C:\oorexx, directory=c:\*
> * 5 *-* pwd = directory2('c:\unknown') -- this one does not exist*
> * 15 *-* raise syntax 48.900 array('Could not change directory to'
> target)*
> * 5 *-* pwd = directory2('c:\unknown') -- this one does not exist*
> *Error 48 running C:\oorexx\test.rex line 15: Failure in system
> service**Error
> 48.900: Could not change directory to c:\unknown*
> *C:\oorexx>*
hope that helps,
Jon
On 5 February 2016 at 03:28, Bertram Moshier <[email protected]>
wrote:
> Hi again,
>
> After reading all of the various comments, I'd like to suggest a future
> for the directory function, which will (hopefully) satisfy everyone.
>
> I think this is the best direction especially when it both matches the
> opening sentence of the current documentation and provides a wide choice of
> useful results. What I mean is having the directory function also return
> the Current Directory makes sense, as it returns information the program
> may not have at the present time. Allowing the directory function to
> return the Current Directory is efficient over coding two lines (e.g. one
> to get the current directory and then to change).
>
>
> I propose the addition of a new parameter (second parameter) to set the
> desired return value. This new parameter would be "C" for Current
> Directory and "N" for New Directory. The default would be "N" thus keeping
> the current ooRexx behavior.
>
> I hope the following clarifies my thoughts:
>
>
> Current_Directory = directory(New_Directory,'c')
> New_Directory_Result = directory(New_Directory('n') also
> New_Directory_Result = directory(New_Directory) would give the same result.
>
>
>
> The documentation would read:
>
> The directory function returns the current directory or changes the
> directory of the current process depending upon the first argument. The
> return value is one of three possible values depending upon the value of
> the first argument, result of the change directory, and the value of the
> second argument. The possible values are the current directory, new
> directory, or null.
>
> If the first argument is null, the function will return the current
> directory. An example is Current_Directory = directory().
>
> If there is first argument, the function will attempt to change to the
> directory location and if successful will return a value depending upon the
> second argument. If the directory change is NOT successful the directory
> function will return a null value.
>
> The second argument returns the current directory, when set to 'C', the
> new directory when set to 'N' or not specified (the default). Using the
> 'c' value for the second argument allows the program to obtain the current
> directory and change the directory in one statement.
>
>
>
> Usage Example:
>
> Current_Directory = directory();
>
> New_Directory = 'C:\users\public\'
> New_Directory_Result = directory(New_Directory,'n') /* OR you can use
> New_Directory_Result = directory(New_Directory) */
> if New_Directory_Result = '' then do
> say 'Directory change was not successful. Most likely' New_Directory
> 'does not exist.'
> exit 1001
> end
>
> New_Directory = 'C:\Temp\MyProgramWorkSpace'
> if directory() = directory(New_Directory,'C') then do
> say New_Directory 'exists and this program changed to it.'
> end
> otherwise do
> 'mkdir' New_Directory
> call directory New_Directory
> if result = '' then do
> say 'Unable to make and change to' New_Directory'.'
> exit 1002
> end
> end
>
>
>
> ------------------------------------------------------------------------------
> Site24x7 APM Insight: Get Deep Visibility into Application Performance
> APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
> Monitor end-to-end web transactions and take corrective actions now
> Troubleshoot faster and improve end-user experience. Signup Now!
> http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
> _______________________________________________
> Oorexx-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/oorexx-users
>
>
------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=272487151&iu=/4140
_______________________________________________
Oorexx-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/oorexx-users