REXX Tips & Tricks, Version 2.80


Inf-HTML [About][Toc][Index] 0.9b (c) 1995 Peter Childs


Check if a directory exists





 
/* sample code to test if a directory exists with restoring all       */
/* directories                                                        */

  do forever
    call lineOut , "Enter the name of the directory to test " ,
                   "(RETURN to end): "
    thisDir = strip( lineIn() )
    if thisDir = "" then
      leave

    if DirExist( thisDir ) <> "" then
      say "The directory <" || thisDir || "> exist."
    else
      say "The directory <" || thisDir || "> does not exist."
  end /* do forever */

exit 0

/* ------------------------------------------------------------------ */
/* function: Check if a directory exists                              */
/*                                                                    */
/* call:     DirExist( testDir )                                      */
/*                                                                    */
/* where:    testDir - name of the directory to test                  */
/*                                                                    */
/* returns:  full name of the directory or "" if the directory        */
/*           don't exist                                              */
/*                                                                    */
DirExist: PROCEDURE
  parse arg testDir .

                        /* init the return code                       */
  thisRC = ""

                        /* install a temporary error handler to check */
                        /* if the drive with the directory to test is */
                        /* ready                                      */
  SIGNAL ON NOTREADY NAME DirDoesNotExist

                        /* check if the drive is ready                */
  call stream testDir || "\*", "D"


                        /* save the current directory of the current  */
                        /* drive                                      */
  curDir = directory()

                        /* save the current directory of the drive    */
                        /* with the directory to test                 */
  curDir1 = directory( fileSpec( "drive", testDir ) )


                        /* test if the directory exists               */
  thisRC = directory( testDir )

                        /* restore the current directory of the drive */
                        /* with the directory to test                 */
  call directory curDir1

                        /* restore the current directory of the       */
                        /* current drive                              */
  call directory curDir
DirDoesNotExist:

return thisRC

  

Inf-HTML End Run - Successful