home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / skeleton.zip / Exist.cmd < prev    next >
OS/2 REXX Batch file  |  1995-08-03  |  4KB  |  81 lines

  1. /*****************************************************************************\
  2. | Checks to see if specified file or directory exists.                        |
  3. |                                                                             |
  4. | $Revision:   1.0  $
  5. |     $Date:   03 Aug 1995 20:10:16  $                                        |
  6. | Libraries:   REXXSAA, REXXUTIL                                              |
  7. |  Category:   Utility                                                        |
  8. |     Class:   Programming                                                    |
  9. |      Type:   File                                                           |
  10. |    Author:   Bob Rice - CompuServe: 72421,3016                              |
  11. |                                                                             |
  12. | Copyright (c) 1995 Empirical Heuristics                                     |
  13. \**************************************************************************r4*/
  14. /*  !tr! = value('TRACE',,'OS2ENVIRONMENT'); parse source . . !who!          */
  15. /*  if !tr! \= '' then say '--> Entering' !who!; trace value !tr!; nop       */
  16.   if arg(1) = '' | left(arg(1),1) = '?' then do
  17.     parse source . . !pgm!; call TellHelp arg(1), !pgm!; exit 2; end
  18.  
  19.   parse arg fn, type .
  20.   exit Exist(fn, type)
  21.  
  22.   /*=========================================================================*\
  23.   | Check if the specified file exists.                                       |
  24.   \*=========================================================================*/
  25. Exist: procedure
  26.   parse arg fn, type
  27.   if type = '' then type = 'F'
  28.   if pos('M', translate(type)) > 0 then multi = 1
  29.                                    else multi = 0
  30.   rc = SysFileTree(fn, 'stem.', type)
  31.   if      \ multi & rc = 0 & stem.0 = 1 then return 1
  32.   else if   multi & rc = 0 & stem.0 = 1 then return stem.0
  33.                                         else return 0
  34. /*--Begin Help-----------------------------------------------------------------
  35. Checks to see if specified file or directory exists.
  36.  
  37. Params: search-arg [,type]
  38.  
  39. search-arg    is a file or directory specification.  Wildcard characters are
  40.               permissible.
  41.  
  42. type          is the type of search argument as follows:
  43.                 F - for a file specification (default)
  44.                 D - for a directory specification
  45.                 B - for either a file or a directory
  46.               The above three parameters are mutually exclusive.
  47.                 M - may be used with any of the above parameters
  48.               When M is not used, the result is always boolean with 1 meaning
  49.               one and only one file or directory matched the specification and
  50.               0 meaning no match was found or multiple matches were found.
  51.               When M is used, the result is the number of matches found.
  52.  
  53. Note: Result is always boolean, even if multiple matches resulting from the use
  54.       of wildcards are found.
  55. ________________
  56. Alternate Params: [ ? | ?? | ??? | ???? ]
  57.  
  58. where:
  59.  
  60.   ?     Displays up to the "Syntax:" or "Params:" portion of this help text.
  61.  
  62.   ??    Displays this entire help text except for the technical information.
  63.  
  64.   ???   Displays this entire help text.
  65.  
  66.   ????  Puts this help text into a file whose name is the same as the name of
  67.         this exec and whose extent is .ABS.  The file is written in the same
  68.         directory as that in which this program resides.
  69.  
  70. _______________
  71. Technical Notes
  72.  
  73. ___________________
  74. Development History
  75.  
  76. $Log:   Q:/rxdv/skeleton/vcs/exist.cm!  $
  77.   
  78.      Rev 1.0   03 Aug 1995 20:10:16
  79.   Initial revision.
  80. --End Help-------------------------------------------------------------------*/
  81.