Product Site

7.4.28. DIRECTORY

Returns the current directory, first 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.

On Windows the returned string includes a drive letter prefix as the first two characters of the directory name. Specifying a drive letter prefix as part of newdirectory causes the specified drive to become the current drive. If a drive letter is not specified, the current drive remains unchanged

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"