home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / spath.zip / SPATH.CMD
OS/2 REXX Batch file  |  1993-11-22  |  3KB  |  102 lines

  1. /*****************************************************************************
  2. ** SPath.cmd - (c) 1993 J. P. Fagerback        Released as FreeWare!        **
  3. **                                                                          **
  4. ** Search the PATH for COM/EXE/CMD/BAT files.                               **
  5. **                                                                          **
  6. ** This REXX 'program' will return the full filename according to Dos and   **
  7. ** OS/2 path search rules.                                                  **
  8. **                                                                          **
  9. ** Syntax: SPath <command>                                                  **
  10. **                                                                          **
  11. ** This code is provided on an as-is basis.  There is no warranty expressed **
  12. ** or implied in the code.  There is no official support for this code.     **
  13. ** However, you are welcome to contact me with questions or comments on the **
  14. ** code.  If you make your own changes to the code and wish to upload the   **
  15. ** modified code to a public forum, please note your modifications to the   **
  16. ** code.                                                                    **
  17. **                                                                          **
  18. ** I can be reached through my CIS id: 100020,3415 or by mail to:           **
  19. **                                                                          **
  20. **     J. P. Fagerback                                                      **
  21. **     PO Box 71 SimensbrÃ¥ten                                               **
  22. **     N-1107 OSLO                                                          **
  23. **     Norway                                                               **
  24. **                                                                          **
  25. *****************************************************************************/
  26.  
  27. /* Load the REXX DLL entry points */
  28. call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  29. call SysLoadFuncs
  30.  
  31. /* Parse the command */
  32. parse arg file
  33. parse upper var file file
  34.  
  35. EnvValue = value("PATH", , "OS2ENVIRONMENT")
  36.  
  37. Count = PathSplit(EnvValue)       /* Set DirList. */
  38.  
  39. do i = 1 to DirList.0
  40.   Filename = DirList.i'\'file'.COM'
  41.   if Exists(Filename) then
  42.     do
  43.     Say Filename
  44.     return
  45.     end
  46.  
  47.   Filename = DirList.i'\'file'.EXE'
  48.   if Exists(Filename) then
  49.     do
  50.     Say Filename
  51.     return
  52.     end
  53.  
  54.   Filename = DirList.i'\'file'.CMD'
  55.   if Exists(Filename) then
  56.     do
  57.     Say Filename
  58.     return
  59.     end
  60.  
  61.   Filename = DirList.i'\'file'.BAT'
  62.   if Exists(Filename) then
  63.     do
  64.     Say Filename
  65.     return
  66.     end
  67.  
  68. end
  69.  
  70. say file 'not found in path'
  71. exit
  72.  
  73.  
  74. PathSplit: procedure expose DirList.
  75.    /**
  76.    ***  This will create a stem variable out of the semicolon-delimited
  77.    ***  variable that is presumably retreived from a PATH or DPATH
  78.    ***  environment.
  79.    **/
  80.  
  81.    arg PathString .
  82.  
  83.    DirList = ''
  84.    j = 1
  85.    parse var PathString DirList.j ';' PathString
  86.    do while DirList.j \= ''
  87.       j = j + 1
  88.       parse var PathString DirList.j ';' PathString
  89.    end /* while */
  90.    DirList.0 = j - 1
  91.    return DirList.0
  92.  
  93. Exists: procedure
  94.  
  95.    arg file
  96.  
  97.    file = stream(file,c,'QUERY EXIST')
  98.    if (file = '') then
  99.       return 0
  100.    else
  101.       return 1
  102.