home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / REX2U10.ZIP / FINDPATH.CMD < prev   
OS/2 REXX Batch file  |  1991-07-16  |  3KB  |  97 lines

  1. /* Find File in a PATH Directory path */
  2. /*            version 1.0  July 15, 1991        */
  3. /*                         Bob Pound            */
  4.  
  5.  
  6. arg filein disdir  
  7.  
  8. if filein="?" then do 
  9.     call help
  10.     exit
  11. end
  12. call Getfile(findfile)
  13. PATH=value("path",,'OS2ENVIRONMENT')
  14. call Displaypath
  15. exit
  16.  
  17.  
  18.  
  19. /* Called Procedures */
  20.  
  21. Displaypath:
  22. /* Display all paths of the PATH variable that contain */
  23. /*         the specified filename                      */
  24. ffcount=0
  25. sp=1
  26. do until ep>=length(path)
  27.     ep=pos(";",path,sp)
  28.     /* if path doesn't end with ;, then a 0 value is returned */
  29.     if ep=0 then ep=length(path)+1
  30.     dir=substr(path,sp,ep-sp)
  31.     if right(dir,1)<>"\"  then dir=dir||"\"
  32.     address cmd "@set z_found=0"
  33.     address cmd "@if exist" dir||findfile "set z_found=1"
  34.     found=value("z_found",,'OS2ENVIRONMENT')
  35.     if found=1 then do
  36.           ffcount=ffcount+1
  37.           if ffcount = 1 then do 
  38.               firstfind=dir
  39.               say findfile "found on:"
  40.           end
  41.           say "  " dir
  42.           if disdir<>"" then  address cmd "@dir" dir||findfile
  43.      end
  44.      sp=ep+1
  45. end
  46. address cmd "@set z_found="
  47. if ffcount=1 then saypath="path"
  48. if ffcount>1 then saypath="paths"
  49. if ffcount > 0 then do
  50.     say findfile "found on" ffcount  saypath
  51.     if lastpos("*",findfile)=0 & lastpos("?",findfile)=0 then say findfile"in" firstfind "will be accessed first."
  52. end
  53. return
  54.  
  55.  
  56. GETFILE: 
  57. findfile=""
  58. do while findfile = ""
  59.   fdrive=filespec("drive",filein)
  60.   if fdrive <> "" then say "Drive not used and is ignored"
  61.   fpath=filespec("path",filein)
  62.   if fpath <> "" then say "Path not used and is ignored"
  63.   findfile=filespec("name",filein)
  64.   if findfile == "" then do
  65.       say "A valid file name is needed for this procedure"
  66.       say "Please enter a valid file name"
  67.       pull filein
  68.   end
  69. end
  70. return(findfile)
  71.  
  72.  
  73. HELP:
  74. say "FINDPATH will locate which directory in your current PATH"
  75. say "environment that a specified file or mask is located in."
  76. say " "
  77. say "FORMAT:"
  78. say "FINDPATH  filename [D]"
  79. say " "
  80. say "    filename - is any accetpable OS/2 file spec name. Wildcards"
  81. say "               accepted.  If this parameter is missing, or invalid you"
  82. say "               prompted for a valid file name."
  83. say "    [D]      - This option parameter is used if you want a directory"
  84. say "               display for the file name when it is located in"
  85. say "               a directory."
  86. say " "
  87. say "EXAMPLES:"
  88. say "        findpath *.cmd"
  89. say "               This will locate all directories in your PATH"
  90. say "               environment that contain *.CMD files"
  91. say "        findpath os2*.ini D"
  92. say "               This will locate all directories in your PATH"
  93. say "               environment that contain OS2*.INI files. For"
  94. say "               ever directory that has those files the"
  95. say "               procedure will display the results of a"
  96. say "               DIR OS2*.INI command."
  97. return