Product SiteDocumentation Site

7.4.28. DIRECTORY


>>-DIRECTORY(--+--------------+--)-----------------------------><
               +-newdirectory-+

Returns the current directory, changing it to newdirectory if an argument is supplied and the named directory exists. If newdirectory is not specified, the name of the current directory is returned. Otherwise, an attempt is made to change to the specified newdirectory. If successful, the name of the newdirectory is returned; if an error occurred, null is returned.
For example, the following program fragment saves the current directory and switches to a new directory; it performs an operation there, and then returns to the former directory.

Example 7.40. Builtin function DIRECTORY

/* get current directory      */
curdir = directory()
/* go play a game             */
newdir = directory("/usr/games")    /* Linux type subdirectory */
if newdir = "/usr/games" then
  do
  fortune   /* tell a fortune */
/* return to former directory */
  call directory curdir
end
else
  say "Can't find /usr/games"